lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

Set-ObjectProperty doesn't appear to alter a field...? #349

Closed carlbeechvuw closed 1 year ago

carlbeechvuw commented 1 year ago

What's going on?

There's a fair number of different sensors that I need to create in our PRTG instance - I hit upon a simple solution that I could create a 'template' device and sensor, and then simply clone them - once cloned, alter any particular fields that are needed.

I've cloned a sensor to a device (AD replication errors sensor), the clone works fine, however, I need to alter the replication partner that it checks against.

I'm using the code : Set-ObjectProperty -id $ClonedSensorDetails.ID -RawProperty datafieldlist_ -RawValue "server1"

However, even after running, the original value remains unchanged - no exceptions / errors are reported by the command.

I have been able to use the code to alter another field (Timeout_) successfully - however, I can see that in PRTG, the replication partner is greyed out, whereas the Timeout field is a normal user-alterable field. I was under the impression that using the RawProperty and RawValue would allow alteration...

I suspect that I'm missing something...?

Due Dilligance

carlbeechvuw commented 1 year ago

Here's a snippet of the get-objectProperty -raw

name : AD_Replication_Errors parenttags : AutoGenerated AutoGenerated AutoGenerated AutoGenerated AutoGenerated AutoGenerated tags : ptfsensor datafieldlist : server2 ptfwriteresult : 0 stack : 0 stackunit : ?raw-s5|# ...

so as far as I can see, 'datafieldlist_' is the correct field and case.. (just in case that was a thought).

Thanks Carl.

lordmilko commented 1 year ago

It sounds like this property is listed as a read-only property in the PRTG UI. While Set-ObjectProperty can actually modify some read-only properties, my experience has been that either not all properties can actually be modified and/or the behavior may be different across various PRTG versions

Rather than clone an existing device/sensor, it may be worth considering creating everything from scratch using PrtgAPI. See Object Creation for further details, and ensure you are using the latest pre-release if using a newer version of PRTG

carlbeechvuw commented 1 year ago

Hi Many thanks for the information - I half suspected as much - the problem is that there's a lot of different types, and to create objects from scratch using the api via program code can take a while - and that isn't efficient if there's only a few instances of that type... (hence the idea to simply use clone and modify 1-2 fields)

Many thanks for checking though :-)