lordmilko / PrtgAPI

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

Add template to existing device #287

Closed fab37100 closed 2 years ago

fab37100 commented 2 years ago

What's going on?

Hi

I was tried to add template on existing device with Get-Device -Id XXXX | Set-ObjectProperty -RawProperty "devicetemplate_" -RawValue 'Template XXXX' but it seems wouldn't work and I don't know if I use this cmdlet correctly.

I've tested the API PRTG and it's the same, I don't know if it's possible.

Due Dilligance

lordmilko commented 2 years ago

Hi @fab37100,

I would imagine in order to do this you would need to use the Get-DeviceTemplate cmdlet to retrieve the template you want to use, and then specify a collection of those as the -RawProperty of Set-ObjectProperty. The DeviceTemplate object that is retrieved will have the proper "value" to use embedded inside of it, which PrtgAPI's request engine will extract when it goes to execute the API request

fab37100 commented 2 years ago

Hi @lordmilko,

Yes I use Get-DeviceTemplate cmdlet to retrieve the template I want to add at the device, but when I give the property Name or Value into Set-ObjectProperty -RawProperty devicetemplate_, it doesn't work and no error has back.

That is different exemple I've used :

$a = get-device -id XXXXXX
$b = Get-DeviceTemplate | ?{$_.name -eq "Template Test.odt"}

$a | Set-ObjectProperty -RawProperty devicetemplate_ -RawValue $b
$a | Set-ObjectProperty -RawProperty devicetemplate_ -RawValue $b.value
$a | Set-ObjectProperty -RawProperty devicetemplate_ -RawValue $b.name

Last month, I was on different subject, sorry for the delay.

kacoroski commented 2 years ago

I had the same problem with groups. Try this:

 get-device -id 12937 | Get-ObjectProperty -RawProperty devicetemplate
NSD-Switch.odt

$template = Get-DeviceTemplate "Generic Device (SNMP Enabled)"

 get-device -id 12937 | set-ObjectProperty -Rawparameters @{ devicetemplate_=1 devicetemplate__check=$template} -force -verbose

get-device -id 12937 | Get-ObjectProperty -RawProperty devicetemplate
Device Generic SNMP.odt
fab37100 commented 2 years ago

Hi @kg7ski,

I used your feedback and it works very well, Thanks ! Now I cannot get all of templates of a device but it's another problem.

Thanks again !