The top answer to this question tells me how to stop/start a remote service. Great. Now, all I need is to wait for the actual stop/start to complete. So, what I\'m looking f
What about powershell and WaitForStatus? Eg, the script below would restart SQL Server on a remote machine:
$computer = "COMPUTER_NAME"
$me = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\user", (convertto-securestring "password" -asplaintext -force)
$restartSqlServer = {
$sqlServer = get-service mssqlserver
$waitInterval = new-timespan -seconds 5
if (-not ($sqlServer.Status -eq "Stopped")) {
$sqlServer.Stop()
$sqlServer.WaitForStatus('Stopped', $waitInterval)
}
$sqlServer.Start()
$sqlServer.WaitForStatus('Running', $waitInterval)
}
icm -ComputerName $computer -ScriptBlock $restartSqlServer -Credential $me