如何在 PowerShell 中显示 Get-Service 输出中的特定属性?
要显示服务中除了默认选项(由 Get-Member 支持)之外的其他属性,你需要将Select-Object (别名 Select)命令通过管道传输。例如,在以下命令中,我们将显示服务名称、启动类型和状态。
命令
Get-Service | Select-Object Name, StartType, Status
输出
Name StartType Status ---- --------- ------ AarSvc_158379 Manual Stopped AdobeARMservice Automatic Running AdobeFlashPlayerUpdateSvc Manual Stopped AJRouter Manual Stopped ALG Manual Stopped AppIDSvc Manual Stopped Appinfo Manual Running AppMgmt Manual Stopped AppReadiness Manual Stopped AppVClient Disabled Stopped AppXSvc Manual Stopped AssignedAccessManagerSvc Manual Stopped AudioEndpointBuilder Automatic Running Audiosrv Automatic Running autotimesvc Manual Stopped AVP20.0 Automatic Running AxInstSV Manual Stopped BcastDVRUserService_158379 Manual Stopped BDESVC Manual Stopped BFE Automatic Running BITS Automatic Running Bluetooth Device Monitor Automatic Running Bluetooth OBEX Service Automatic Running BluetoothUserService_158379 Manual Stopped BrokerInfrastructure Automatic Running
命令
你也可以通过 Sort-Object 对对象的属性进行排序。在以下示例中,服务按其启动类型排序。
Get-Service | Select Name,Status,StartType | Sort-Object StartType
输出
Audiosrv Running Automatic CDPUserSvc_158379 Running Automatic BrokerInfrastructure Running Automatic DellClientManagementService Running Automatic Bluetooth Device Monitor Running Automatic BFE Running Automatic BITS Running Automatic AdobeARMservice Running Automatic ZeroConfigService Running Automatic DeviceAssociationService Running Automatic Bluetooth OBEX Service Running Automatic Dell Hardware Support Running Automatic DDVRulesProcessor Running Automatic svsvc Stopped Manual WPDBusEnum Stopped Manual stisvc Stopped Manual StorSvc Running Manual vmickvpexchange Stopped Manual swprv Stopped Manual SstpSvc Running Manual workfolderssvc Stopped Manual SSDPSRV Running Manual WpcMonSvc Stopped Manual SNMPTRAP Stopped Manual spectrum Stopped Manual StateRepository Running Manual SDRSVC Stopped Manual XblAuthManager Stopped Manual
广告