Advertisement
stephanlinke

Untitled

Nov 11th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Requires -Modules Microsoft.PowerShell.Management, Microsoft.PowerShell.Utility
  2. #This script will restart the PRTG probe service on a remote host
  3. #(c) 2015 Stephan Linke, Paessler AG
  4. #example parameters:
  5. #-Computer "%host" -SensorID %sensorid -PRTGHost "prtg.mycompany.com" -PRTGUser "prtgadmin" -PRTGhash "12345678"
  6. param($computer = "" ,$service = "PRTG Probe Service", $sensorid = 1, $PRTGhost,$PRTGuser,$PRTGhash);
  7.  
  8. # pause the original sensor so we don't get stuck in a reboot loop
  9. Invoke-Webrequest "http://$($PRTGhost)/api/pause.htm?id=$($sensorid)&pausemsg=PRTG restarted due to high CPU usage&action=0&username=$($PRTGuser)&passhash=$($PRTGhash)" | Out-Null
  10.  
  11. # create a new service object for the remote probe host
  12. $SVC = new-Object System.ServiceProcess.ServiceController($service,$computer)
  13.  
  14. # stop the original, wait for it to stop and restart the service
  15. $SVC.Stop();
  16.  
  17. # Modify the timeout if necessary
  18. $SVC.WaitForStatus('Stopped', (new-timespan -seconds 60))
  19. if ( ($SVC.get_Status()) -ieq "Stopped" ) {
  20.     $SVC.Start();
  21.     # resume the original sensor
  22.     Invoke-Webrequest "http://$($PRTGhost)/api/pause.htm?id=$($sensorid)&action=1&username=$($PRTGuser)&passhash=$($PRTGhash)" | Out-Null
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement