PS: Services

Command to display services whose name matching given string

PS C:> Get-Service | Where-Object {$_.DisplayName -match "citrix" } | ft Name, DisplayName

Name                                                        DisplayName
----                                                        -----------
CdfSvc                                                      Citrix Diagnostic Facility COM Server
CdmService                                                  Citrix Client Network
Citrix 64-bit Virtual Memory Optimization                   Citrix 64-bit Virtual Memory Optimization
Citrix Encryption Service                                   Citrix Encryption Service
Citrix EUEM                                                 Citrix End User Experiencing Monitoring
Citrix Virtual Memory Optimization                          Citrix Virtual Memory Optimization
CitrixHealthMon                                             Citrix Health Monitoring and Recovery
CitrixWMIService                                            Citrix WMI Service
CitrixXTEServer                                             Citrix XTE Server
cpsvc                                                       Citrix Print Manager Service
CTXCPUBal                                                   Citrix CPU Utilization Mgmt/CPU Rebalancer
ctxcpuSched                                                 Citrix CPU Utilization Mgmt/Resource Mgmt
IMAAdvanceSrv                                               Citrix Services Manager
IMAService                                                  Citrix Independent Management Architecture
MFCom                                                       Citrix MFCOM Service
RadeSvc                                                     Citrix Streaming Service
xensvc                                                      Citrix Tools for Virtual Machines Service

PS C:>

Query multiple services status at once:

PS C:> Get-Service | Where-Object {$_.DisplayName -match "windows" -OR $_.DisplayName -match "SQL" } | ft Name, Display
Name, Status -auto

Name                   DisplayName                                           Status
----                   -----------                                           ------
AudioSrv               Windows Audio                                        Stopped
FontCache3.0.0.0       Windows Presentation Foundation Font Cache 3.0.0.0   Stopped
idsvc                  Windows CardSpace                                    Stopped
MsDtsServer100         SQL Server Integration Services 10.0                 Running
MSIServer              Windows Installer                                    Stopped
MSSQLFDLauncher        SQL Full-text Filter Daemon Launcher (MSSQLSERVER)   Running
MSSQLSERVER            SQL Server (MSSQLSERVER)                             Running
MSSQLServerADHelper100 SQL Active Directory Helper Service                  Stopped
MSSQLServerOLAPService SQL Server Analysis Services (MSSQLSERVER)           Running
ReportServer           SQL Server Reporting Services (MSSQLSERVER)          Running
SharedAccess           Windows Firewall/Internet Connection Sharing (ICS)   Running
SQLBrowser             SQL Server Browser                                   Running
SQLSERVERAGENT         SQL Server Agent (MSSQLSERVER)                       Running
SQLWriter              SQL Server VSS Writer                                Running
stisvc                 Windows Image Acquisition (WIA)                      Stopped
UMWdf                  Windows User Mode Driver Framework                   Stopped
W32Time                Windows Time                                         Running
winmgmt                Windows Management Instrumentation                   Running
Wmi                    Windows Management Instrumentation Driver Extensions Running

PS C:>

To query services based on their status:

Get-Service | Where-Object {$_.status -eq “stopped”}
Get-Service | Where-Object {$_.status -eq “running”}
Get-Service | Sort-Object status,displayname

Remotely manage services:

(gwmi -computername remotepc -class win32_service “Name=’alerter’”).stopservice()
(gwmi -computername remotepc -class win32_service “Name=’alerter’”).startservice()
Invoke-Command -ComputerName Server01 {Restart-Service Spooler} (Needs Remoting feature that comes with PSv2)

Display the services status in color:

PS C:> Get-Service | Where-Object {$_.DisplayName -match “windows” -OR $_.DisplayName -match “SQL” } | ForEach-Object { if ($_.status -eq “Running”) { write-host $_.name    $_.DisplayName    $_.Status -foreground Green} else { write-host $_.name    $_.DisplayName    $_.Status -foreground Red} }

 

Leave a Reply

Your email address will not be published. Required fields are marked *