Comments these days:

Powershell-Tips has crossed 4,00,000 views. If you are stuck with any Powershell script, do send mail to me.

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 -
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 alot with Powershell and submit them for you.. Please send your comments and mails to me...

Happy scripting!!

No comments:

Post a Comment