如何在 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
廣告