How to get services based on multiple conditional parameters in PowerShell?


To filter out services with both start-type “Automatic” and Status “stopped” we need to use the -AND comparison operator. Here, services will be displayed only when both conditions are matching.

Command

Get-Service | where{($_.StartType -eq "Automatic") -and ($_.Status -eq "Stopped")} |
Select Name, StartType, Status

Output

Name       StartType  Status
----       ---------  ------
gpsvc      Automatic Stopped
gupdate    Automatic Stopped
MapsBroker Automatic Stopped

Command

To get services with start-type manual or disabled we will use -OR operator.

Get-Service | where{($_.StartType -eq "Manual") -or ($_.StartType -eq "Disabled")} |
Sort-Object Starttype | Select Name, StartType, Status

Output

LxpSvc                                                    Manual Stopped
lmhosts                                                   Manual Running
KtmRm                                                     Manual Stopped
IpxlatCfgSvc                                              Manual Stopped
FontCache3.0.0.0                                          Manual Running
KeyIso                                                    Manual Running
klvssbridge64_20.0                                        Manual Stopped
UevAgentService                                         Disabled Stopped
tzautoupdate                                            Disabled Stopped
NetTcpPortSharing                                       Disabled Stopped
ssh-agent                                               Disabled Stopped
shpamsvc                                                Disabled Stopped
RemoteRegistry                                          Disabled Stopped
AppVClient                                              Disabled Stopped
svcdemo                                                 Disabled Stopped

Updated on: 22-Jan-2020

429 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements