如何使用 PowerShell 中的 WMI 方法获取服务信息?

powershellmicrosoft technologiessoftware & coding

您也可以使用 WMI 方法获取服务信息,而不是使用标准命令 Get-Service。

命令

要获取服务器上的服务信息,您需要使用 WMI 类 Win32_Service。

Get-WmiObject -Class Win32_Service

输出

ExitCode  : 0
Name      : Browser
ProcessId : 0
StartMode : Manual
State     : Stopped
Status    : OK

ExitCode  : 0
Name      : BTAGService
ProcessId : 1468
StartMode : Manual
State     : Running
Status    : OK

ExitCode  : 0
Name      : BthAvctpSvc
ProcessId : 1460
StartMode : Manual
State     : Running
Status    : OK

ExitCode  : 0
Name      : bthserv
ProcessId : 1480
StartMode : Manual
State     : Running
Status    : OK

命令

您可以使用 Select-Object 过滤特定输出。

Get-WmiObject win32_Service | Select-Object Name, State, Startmode

输出

Name                                                   State   Startmode
----                                                   -----   ---------
AdobeARMservice                                        Running Auto
AdobeFlashPlayerUpdateSvc                              Stopped Manual
AJRouter                                               Stopped Manual
ALG                                                    Stopped Manual
AppIDSvc                                               Stopped Manual
Appinfo                                                Running Manual
AppMgmt                                                Stopped Manual
AppReadiness                                           Stopped Manual
AppVClient                                             Stopped Disabled
AppXSvc                                                Stopped Manual
AssignedAccessManagerSvc                               Stopped Manual
AudioEndpointBuilder                                   Running Auto
Audiosrv                                               Running Auto
autotimesvc                                            Stopped Manual
AVP20.0                                                Running Auto
AxInstSV                                               Stopped Manual
BDESVC                                                 Stopped Manual
BFE                                                    Running Auto
BITS                                                   Running Auto
Bluetooth Device Monitor                               Running Auto
Bluetooth OBEX Service                                 Running Auto

使用 WMI 获取远程计算机上的服务。

Get-WmiObject win32_Service –ComputerName Win7,Test-PC | Select-
Object Name, State, Startmode

相关文章