I am trying to set an elements template through OSIsoft.powershell, unfortunately I can not seem to get the proper syntax. Any help would be much appreciated.
You should use AFElementTemplate object instead of using the name P001.CISCO.Router.2800. So, whatever return from Get-AFElementTemplate will be a variable to replace P001.CISCO.Router.2800.
Would Set-AFElementTemplate command from https://techsupport.osisoft.com/Documentation/PI-Powershell/PI-AF/Set-AFElementTemplate.html work?
There is an example at the bottom of the document.
I don't believe there is a direct way to do this using the PowerShell cmdlets. Set-AFElement is the cmdlet that should be used to edit a particular AF element, and it does not look like it includes an option to change the template. If you must do it via the existing PowerShell cmdlets, you would probably need to copy the element's properties and create a new element under the desired template. Otherwise another option would be to call AFSDK in your PowerShell script and do it via AFSDK.
The Add-AFElement command has an –AFElementTemplate option and when I pass in the command “Add-AFElement -Name BestRouter -AFElementTemplate P001.CISCO.Router.2800 -AFElement $element4”
it throws an error saying “Cannot use Element Template ‘P001.CISCO.Router.2800’ until it has been added to a collection.” I am able to see that particular template when I run Get-AFElementTemplate for this database. I am uncertain what collection it is referring too.
That is awesome. It works.
Awesome, if your question is being answered. Could you mark one of the reply as answer? So other member can benefit from this post as well. Thanks.
Retrieving data ...