Hi,

PRTG sometimes sets a comment on a device automatically. I did'n knew that. And now, after i cloned many many devices, i have many comments in that devices not showing correct Content. Because i don't use the "Comments" at the Moment, it would be great if i could delete/wipe all comments from devices/sensors.

Is there a way i can do that without clicking in every device (500+) and remove the comment manualy?

Thanks.


Article Comments

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.


Nov, 2018 - Permalink