Friday, August 22, 2014

#23 : Find the List of Services Running or Stopped

While programming a script, I wanted to know if specific service is running or not. To accomplish it, I used Get-Service cmdlet. Get-Service gives you details about all the Windows Services.

1. Get the name of services, status and description about all services -
Get-Service

2. Get the details of services running -
Get-Service | where { $_.Status -eq "Running" }

3. Get the details of services stopped -
Get-Service | where { $_.Status -eq "Stopped" } 

4. Find if specific service is running or not and do some operation -
$SPOOL_SRV_STATUS=Get-Service | Where { $_.name -eq "Spooler" } | foreach {$_.Status}


if ( $SPOOL_SRV_STATUS -eq "Running" ) 


    echo "Service is running ... " 
    #--Do any operation --#   

else
{
    
    echo "Service is not running ... " 
    #--Do any operation --# 


}

I play a lot with Powershell and submit them for you.. Please send your comments and mails to me...

Happy scripting!!

No comments:

Post a Comment

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...