powershell newbie help

im trying to write a script that will stop a service if it is running or start a service if it is stopped this is what i have so far and im just not understanding why this isnt working

{$ServiceName = 'xbgm' $arrService = Get-Service -Name $ServiceName if ($arrService.Status -ne 'running') { Start-Service $ServiceName write-host $arrService.status write-host 'Service starting' $arrService.Refresh() if ($arrService.Status -eq 'Running') { Write-Host 'Service is now Running' } else { Stop-service $servicename $arrservice.Refresh() write-host $arrService.Status write-host 'service stopping' } start-sleep -seconds 10 } } } 

submitted by /u/octavi0us
[link] [comments]

Leave a Reply