lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
305 stars 38 forks source link

Obtaining ID from newly cloned or created object in an automation script #182

Closed Trynidia closed 3 years ago

Trynidia commented 3 years ago

Hey,

I am attempting to write a Powershell Script that will prove useful in my business to automate a lot of our processes in creating PRTG monitoring for new infrastructure.

I currently have automation working through a method where I must drill down very far for each sensor creation or edit: Get Group X | Get-Group Y | Get Device Z | Clone-Object -Source ID 123 -Resume

This does work quite well but is tedious and the script will need updating as new sensors are added to our pool.

I am cloning some sensor factory sensors and would like to be able to change the channel definitions immediately after creating them in the script, all automatically with no human input. The cloned factory sensors will be pointing to incorrect devices, i need them pointing to some new sensors created earlier in the script.

I notice that when I clone an object it returns to me the name and other properties including ID of the new sensor. Is it possible to select only this ID? Read this ID output and assign it as a variable in the script? Capture

I have tried to make a variable such as: $newobject = Get Group X | Get-Group Y | Get Device Z | Clone-Object -Source ID 123 -Resume

Doing Write-Host $newjobject after this only returns the name of the cloned object (in this case "AM Layer Processing). No other properties. image If I try to do object manipulation with this variable it will make the change to all sensors with the same name. I want to do it by ID.

If this at all possible? I have searched vigorously through the documentation.

Many thanks!

Due Dilligance Please enter an 'x' between the brackets to indicate you have done these

lordmilko commented 3 years ago

Hi @Trynidia,

If you do $newobject.Id you will get the ID of the object

Please let me know if you have any further issues

Regards, lordmilko

Trynidia commented 3 years ago

Hi @Trynidia,

If you do $newobject.Id you will get the ID of the object

Please let me know if you have any further issues

Regards, lordmilko

Cheers this works perfectly for my needs. Seemed pretty obvious but I am new to PowerShell.