Skip to content

Instantly share code, notes, and snippets.

@owlfox
Created January 18, 2018 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owlfox/03083149c357360e6d8537b114432e14 to your computer and use it in GitHub Desktop.
Save owlfox/03083149c357360e6d8537b114432e14 to your computer and use it in GitHub Desktop.
Check if ntp service running and try to start it in powershell, if failed prompt!
$sname="w32time"
#check if the service running
if((Get-service $sname | Where-Object {$_.status -eq "running"} ) -eq $Null){
#Not Running, restart it
Stop-service $sname
Start-service $sname
}
sleep 30
#still not Running, prompt
if((Get-service $sname | Where-Object {$_.status -eq "running"} ) -eq $Null){
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") #load messagebox lib
[System.Windows.Forms.MessageBox]::Show($sname + " is not running, please contact with Admin.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment