Greetings Programs…
I need help in understanding how to correctly add multiple targets to my action.xml template. At this point I’m not sure if I am having issues understanding the BES.xml, issues understanding how to properly modify XML with PowerShell, or maybe both. I’m reaching out here first in hopes someone with BigFix knowledge can at least point in me a useful direction.
I have a working powershell script that that utilizes the API to upload a file, create a task, and then take an action against that task. The script’s current single parameter is the package name to pull from a Nexus repository and I would now like to add a parameter to pass in targets.
I have been using the below code and XML snippet with hardcoded ComputerName and now need to make them dynamic based on the passed in values. Currently I use the below code to modify the XML and set <FixletID>
to the value returned by the create task function.
I’ve tried a number of ways to make the same general type of change against <Target>
and <ComputerName>
but running into error after error.
` $FixletID = $TaskObject.BESAPI.Task.ID
Write-Log "Creating action against Task ID $FixletID"
$stubTemplate = "$PSScriptRoot\ActionTemplate.xml"
$global:myXML = New-Object xml
$myXML.Load($stubTemplate)
$myXML.BES.SourcedFixletAction.SourceFixlet.FixletID = $FixletID
$body = $global:myXML
<?xml version="1.0" encoding="UTF-8"?>
<BES xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BES.xsd">
<SourcedFixletAction>
<SourceFixlet>
<Sitename>Our Cool Site Name</Sitename>
<FixletID>SOMENUMBER</FixletID>
<Action>Action1</Action>
</SourceFixlet>
<Target>
<ComputerName>computer001</ComputerName>
<ComputerName>computer002</ComputerName>
<ComputerName>computer003</ComputerName>
</Target>
</SourcedFixletAction>
</BES> `
From the XML above are the “ComputerName” lines considered XML elements? When I ask PowerShell about the various nodes I get the following;
myXML System.Xml.XmlDocument
BES System.Xml.XmlElement
SourcedFixletAction System.Xml.XmlElement
Target System.Xml.XmlElement
ComputerName System.String`
I see the below in BES.xml but it isn’t helping me much.
<xs:complexType name="BESActionTarget"> <xs:choice> <xs:element name="ComputerName" type="xs:normalizedString" maxOccurs="unbounded" /> <xs:element name="ComputerID" type="xs:nonNegativeInteger" maxOccurs="unbounded" /> <xs:element name="CustomRelevance" type="xs:normalizedString" maxOccurs="1"/> <xs:element name="AllComputers" type="xs:boolean" maxOccurs="1" /> </xs:choice> </xs:complexType>
If I try and set the value of computername to another string …
$myXML.BES.sourcedFixletAction.target.computername = [string]"somestring"
it throws an error that “only strings can be used as values to set XmlNode properties.”
What type of XML construct are the ComputerName lines?