PrtgAPI icon indicating copy to clipboard operation
PrtgAPI copied to clipboard

Add template to existing device

Open fab37100 opened this issue 3 years ago • 3 comments
trafficstars

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

  • [X] It wasn't covered by the wiki, I swear!
  • [X] I have tried doing some basic research on this issue but haven't been able to come up with anything. Please help!

fab37100 avatar Jun 01 '22 08:06 fab37100

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

lordmilko avatar Jun 01 '22 11:06 lordmilko

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.

fab37100 avatar Jul 04 '22 10:07 fab37100

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

kacoroski avatar Jul 27 '22 18:07 kacoroski

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 !

fab37100 avatar Sep 30 '22 14:09 fab37100