Home > Exchange Server > One Liners: Restarting Stopped Services

One Liners: Restarting Stopped Services

PowerShell-logo-128x84During a recent power “issue”, I had to restart an entire rack full of Hyper-V servers. While an Exchange VM was booting, a networking issue caused the VM to not be able to connect to anything else, including domain controllers. As a result, many services couldn’t start. Rather than bouncing the server, or manually starting the services, this little one liner came in handy. Unfortunately, Get-Service doesn’t expose the startmode. That would make it too easy. So, we use Get-WMIObject:

Get-WMIObject win32_service | Where-Object {$_.name -match "exchange" -and $_.startmode -eq "Auto" -and $_.state -ne "running"} | Start-Service

Of course, we can remove the name check and look for all services on the server that should be (but aren’t) started, and start them:

Get-WMIObject win32_service | Where-Object {$_.startmode -eq "Auto" -and $_.state -ne "running"} | Start-Service

Ståle Hansen has reminded me that in Lync, there is also another solution:

Get-CsWindowsService -ExcludeActivityLevel | Where-Object {$_.Status -like "Stopped"} | Start-CsWindowsService
  1. August 13th, 2013 at 11:21 | #1

    You should use a WMI Filter instead of Where-Object to be more efficient.

    This should also work remotely:
    Get-WMIObject win32_service -filter “name like ‘%exchange’% AND startmode=’Auto’ AND state =’Stopped'” -computer EXCH01 | Invoke-WMIMethod -name StartService

  2. Marc Ferrazzano
    January 1st, 2015 at 18:40 | #2

    Hi, can you do this on a remote machine ??

  1. April 17th, 2014 at 11:46 | #1
  2. April 4th, 2016 at 00:07 | #2