Advertisement
stephanlinke

Untitled

Jan 14th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $prtgurl = "http://127.0.0.1:80"
  2. $prtguser= ""
  3. $passhash= ""
  4. $oldcompany = "one"
  5. $newcompany = "two"
  6.  
  7. ## /!\ don't change anything below /!\ ##
  8. $apicall  = "/api/table.json?content=groups&output=json&columns=objid,name"
  9. $devices = "/api/table.json?content=devices&output=json&columns=objid,name"
  10.  
  11. $apiGroups  = [string]::Format("{0}/api/table.json?content={1}&output=json&columns=objid,name&username={2}&passhash={3}",$prtgurl,"groups",$prtguser,$passhash)
  12. $apiDevices = [string]::Format("{0}/api/table.json?content={1}&output=json&columns=objid,name&username={2}&passhash={3}",$prtgurl,"devices",$prtguser,$passhash)
  13.  
  14. $Groups  = (Invoke-WebRequest $apiGroups | ConvertFrom-Json)
  15. $Devices = (Invoke-WebRequest $apiDevices | ConvertFrom-Json)
  16.  
  17. foreach($group in $Groups.groups){
  18.     if($group.name -match $oldcompany){
  19.         $name = $group.name -replace $oldcompany,$newcompany
  20.         Invoke-WebRequest ([string]::Format("{0}/api/rename.htm?id={1}&value={2}&username={3}&passhash={4}", $prtgurl,$group.objid,$name,$prtguser,$passhash)) | Out-Null;
  21.     }
  22. }
  23.  
  24. foreach($Device in $Devices.devices){
  25.     if($Device.name -match $oldcompany){
  26.         $name = $Device.name -replace $oldcompany, $newcompany
  27.         Invoke-WebRequest ([string]::Format("{0}/api/rename.htm?id={1}&value={2}&username={3}&passhash={4}", $prtgurl,$device.objid,$name,$prtguser,$passhash)) | Out-Null;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement