Check Windows Service Status – PowerShell Script

  1. Copy and save the below script as CheckMyService.ps1
  2. Open Powershell and navigate to the path where the script is saved
  3. Simply type part of the script name and then press tab for auto-complete
  4. You have to provide a service name as part of the script parameter

 

Leave a Reply

1 Comment on "Check Windows Service Status – PowerShell Script"

avatar
  Subscribe  
newest oldest most voted
Notify of
Eddie
Guest

Quick questions..
1.If I have more than one service that I need to check status, should I just add the new condition to the same if statement?
Example:

if (Get-Service $Print Spooler -and $WalletService -ErrorAction SilentlyContinue)

——————–
2. Does it work if I have spaces in the service name?

Like this:

param (
[Parameter(Mandatory=$true)]
[string] $Print Spooler
)
 
if (Get-Service $Print Spooler -ErrorAction SilentlyContinue)
{
if ((Get-Service -Name $Print Spooler).Status -eq ‘Running’)
{
$ServiceStatus = (Get-Service -Name $Print Spooler).Status
Write-Host $Print Spooler “-” $ServiceStatus
}
elseif ((Get-Service -Name $Print Spooler).Status -eq ‘Stopped’)
{
$ServiceStatus = (Get-Service -Name $Print Spooler).Status
Write-Host $ServiceName “-” $ServiceStatus
}
else
{
$ServiceStatus = (Get-Service -Name $Print Spooler).Status
Write-Host $Print Spooler “-” $ServiceStatus
}
}
else
{
Write-Host “$Print Spooler not found”
}

———————

Thank you so much!

Best regards,
Eddie