lordmilko / PrtgAPI

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

Get-ObjectProperty : Could not deserialize value 'WriteResultToDisk' as it is not a valid member of type 'PrtgAPI.DebugMode' #333

Open MikeSouthwell opened 1 year ago

MikeSouthwell commented 1 year ago

Can someone please assist with the following error?

I'm trying to customise the "microsoft365sensor" type. However, when I try to pipe Get-Object Property to Get-Sensor it throws the following error (I want to change the Search for field under Filter by Subject, but I don't know what the -RawProperty would be):

`Get-Sensor -Name $clientSubject | Get-ObjectProperty

Get-ObjectProperty : Could not deserialize value 'WriteResultToDisk' as it is not a valid member of type 'PrtgAPI.DebugMode'. Could not process XML 'WriteResultToDisk'. At line:1 char:35

lordmilko commented 1 year ago

The DebugMode property of a given object has historically been one of the following three values on several sensor types:

You can see that "WriteResultToDisk" is slightly different. I will need to investigate whether this is unique to this sensor type or PRTG have renamed one of the previous historical values

In the meantime, you can work around this by instead asking PrtgAPI to emit raw object properties

Get-Sensor $clientSubject | Get-ObjectProperty -Raw
MikeSouthwell commented 1 year ago

Thanks lordmilko,

When I try and run that command it doesn't return anything.

It could be that that sensor type doesn't have any Raw values?

I just want to change the Search for field value under Filter by Subject

lordmilko commented 1 year ago

Can you confirm that Get-Sensor $clientSubject returns something?

You will need to set the $clientSubject variable again if you execute this in a fresh PowerShell session

MikeSouthwell commented 1 year ago

It doesn't return anything, but it doesn't return an error either. The $clientSubject variable is working and I have confirmed that when I just run $clientSubject it does output the intended variable it is storing.

lordmilko commented 1 year ago

This (likely) means the $clientSubject variable does not exactly match the name of the sensor

For the purposes of this issue, can you try and do Get-Sensor -Id <id> instead, where ID is the ID of the sensor shown in the URL, then do Get-Sensor -Id <id> | Get-ObjectProperty -Raw

lordmilko commented 1 year ago

If the sensor name contains wildcard characters that can cause an issue: specifically *, ?, [ and ]

MikeSouthwell commented 1 year ago

I got it working now. Thanks @lordmilko!

For anyone else, this is the PowerShell code required:

Get-Sensor -Name $clientSubject | Set-ObjectProperty -RawProperty paessler-microsoft365-mailbox_section-mailbox_group-filter_subject_string_ -RawValue "$subjectString" -Force

Timmeeh commented 4 months ago

I get a similar result for the sensors of type REST Custom v2 (BETA). PRTG 24.1.92.1554.

get-sensor -tags rest | Get-ObjectProperty -RawProperty writeresult returns DiscardResult for all ~100 of them.

So it seems some PRTG sensors can now also return a string instead of integer values?