Comments these days:

PS I:> Add-Thought "Success is journey, not destination."

Monday, January 16, 2012

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 -

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 { $ -eq "Spooler" } | foreach {$_.Status}

if ( $SPOOL_SRV_STATUS -eq "Running" ) 

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

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


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

Happy scripting!!

No comments:

Post a Comment