Skip to content

Instantly share code, notes, and snippets.

@greenygh0st
Last active October 22, 2021 19:34
Show Gist options
  • Save greenygh0st/a63a806760be1ddd27acd6cccf4dc7d2 to your computer and use it in GitHub Desktop.
Save greenygh0st/a63a806760be1ddd27acd6cccf4dc7d2 to your computer and use it in GitHub Desktop.
A script for starting and stepping Windows services in a controlled and non-error inducing way...
$ServiceName = 'Serenade'
$arrService = Get-Service -Name $ServiceName
while ($arrService.Status -ne 'Running')
{
Start-Service $ServiceName
write-host $arrService.status
write-host 'Service starting'
Start-Sleep -seconds 5
$arrService.Refresh()
if ($arrService.Status -eq 'Running')
{
Write-Host 'Service is now Running'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment