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

PowerShellMicrosoft TechnologiesSoftware & Coding

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
raja
Published on 22-Jan-2020 08:03:35
Advertisements