Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires -Modules Microsoft.PowerShell.Management, Microsoft.PowerShell.Utility
- #This script will restart the PRTG probe service on a remote host
- #(c) 2015 Stephan Linke, Paessler AG
- #example parameters:
- #-Computer "%host" -SensorID %sensorid -PRTGHost "prtg.mycompany.com" -PRTGUser "prtgadmin" -PRTGhash "12345678"
- param($computer = "" ,$service = "PRTG Probe Service", $sensorid = 1, $PRTGhost,$PRTGuser,$PRTGhash);
- # pause the original sensor so we don't get stuck in a reboot loop
- 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
- # create a new service object for the remote probe host
- $SVC = new-Object System.ServiceProcess.ServiceController($service,$computer)
- # stop the original, wait for it to stop and restart the service
- $SVC.Stop();
- # Modify the timeout if necessary
- $SVC.WaitForStatus('Stopped', (new-timespan -seconds 60))
- if ( ($SVC.get_Status()) -ieq "Stopped" ) {
- $SVC.Start();
- # resume the original sensor
- Invoke-Webrequest "http://$($PRTGhost)/api/pause.htm?id=$($sensorid)&action=1&username=$($PRTGuser)&passhash=$($PRTGhash)" | Out-Null
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement