如何在PowerShell中基于启动类型获取服务?

以下命令可用于根据服务的启动类型(自动,手动或禁用)过滤服务。

命令

获取自动启动类型服务。这些服务会在系统启动时自动启动。

Get-Service | where{$_.StartType -eq "Automatic"} | Select Name, Starttype

输出结果

SystemEventsBroker          Automatic
TeraCopyService             Automatic
Themes                      Automatic
TrkWks                      Automatic
UserManager                 Automatic
UsoSvc                      Automatic
VMUSBArbService             Automatic
WavesSysSvc                 Automatic
Wcmsvc                      Automatic
Winmgmt                     Automatic
WlanSvc                     Automatic
WpnService                  Automatic
WpnUserService_158379       Automatic
wscsvc                      Automatic
WSearch                     Automatic
ZeroConfigService           Automatic

命令

获取手动启动类型服务。这些服务需要手动启动,并且在系统启动时不会自动启动。它们可以由用户或应用程序触发。

Get-Service | where{$_.StartType -eq "Manual"} | Select Name, Starttype

输出结果

WinRM                                                     Manual
wisvc                                                     Manual
wlidsvc                                                   Manual
wlpasvc                                                   Manual
WManSvc                                                   Manual
wmiApSrv                                                  Manual
WMPNetworkSvc                                             Manual
workfolderssvc                                            Manual
WpcMonSvc                                                 Manual
WPDBusEnum                                                Manual

命令

获取“禁用”启动类型服务。这些类型的服务在无用时会被用户或系统管理员禁用。

Get-Service | where{$_.StartType -eq "Disabled"} | Select Name, Starttype

输出结果

Name              StartType
----              ---------
AppVClient         Disabled
NetTcpPortSharing  Disabled
RemoteAccess       Disabled
RemoteRegistry     Disabled
shpamsvc           Disabled
ssh-agent          Disabled
svcdemo            Disabled
tzautoupdate       Disabled
UevAgentService    Disabled