Hi there,
I adapted an existing script that I had laying around. This will gather a list of sensors, then delete the comments for all sensors, then get a list for devices and delete the comments there as well.
To use it, please change the parameters in the first three lines of the script:
- $username = username of an administrative user within PRTG
- $passhash = passhash of that user (Setup > System Administration > User Accounts > USER > Show Passhash)
- $prtgserver = URL of your PRTG Server (e.g. "https://mycoolprtgserver")
$username = "prtgadmin"
$passhash = "1278894095"
$prtgserver = "http://mycoolprtgserver"
$conerror = "0" # DO NOT CHANGE!
# Check URL
$prtgserverlength = $prtgserver.Length - 1
$prtgserverlastch = $prtgserver.Substring($prtgserverlength)
if ($prtgserverlastch -eq "/"){
$prtgserver = $prtgserver.Substring(0,$prtgserver.Length - 1)
}
# Check connectivity
try{
$conurl = [String]::Format("{0}/api/table.json?content=sensors&columns=objid,name&username={1}&passhash={2}",$prtgserver,$username,$passhash)
Invoke-WebRequest -Uri $conurl | Out-Null
} catch {
$conerror = "1"
Write-Host "Something went wrong. Please check the parameters above. :("
}
if($conerror -eq "0"){
# Sensors
Write-Host "Delete Comments for Sensors:"
# Get Sensors
$sensorsurl = [String]::Format("{0}/api/table.json?content=sensors&columns=objid,name&username={1}&passhash={2}",$prtgserver,$username,$passhash)
$sensorids = Invoke-WebRequest $sensorsurl -UseBasicParsing | ConvertFrom-JSON | Select -expand sensors
# Get Inherit or Not Sensors
foreach($sensorid in $sensorids.objid) {
$inheriturl = [String]::Format("{0}/editsettings?id={1}&comments_=&username={2}&passhash={3}",$prtgserver,$sensorid,$username,$passhash)
$inheritsite = Invoke-WebRequest $inheriturl -UseBasicParsing
Write-Host "Comment deleted for Sensor-ID: " -NoNewline
Write-Host "$($sensorid)" -foreground Red
}
# Devices
Write-Host " "
Write-Host "Delete Comments for Devices:"
# Get Devices
$devicesurl = [String]::Format("{0}/api/table.json?content=devices&columns=objid,name&username={1}&passhash={2}",$prtgserver,$username,$passhash)
$deviceids = Invoke-WebRequest $devicesurl -UseBasicParsing | ConvertFrom-JSON | Select -expand devices
# Get Inherit or Not Devices
foreach($deviceid in $deviceids.objid) {
$inheriturl = [String]::Format("{0}/editsettings?id={1}&comments_=&username={2}&passhash={3}",$prtgserver,$deviceid,$username,$passhash)
$inheritsite = Invoke-WebRequest $inheriturl -UseBasicParsing
Write-Host "Comment deleted for Device-ID: " -NoNewline
Write-Host "$($deviceid)" -foreground Red
}
}
Best regards.
Add comment