It's been a long while since I've dealt with Powershell, but I'm in need of a method by which to generate a large XML file from a template that I've created.
The XML I'm dealing with looks like this:
<Project>
<Groups>
<GroupConfig typeKey="standard" name="$t" path="TTC/TTC1">
<Property name="CONFIGURED_ITEMS" isComplex="true">
<ItemConfig name="Bot_Setpoint" typeId="0">
<Property name="TARGET_DATA_TYPE">4</Property>
<Property name="SCALEDHIGH">0.1</Property>
<Property name="ALERTMESSAGEMODE">0</Property>
<Property name="RAWLOW">0.0</Property>
<Property name="ALERTMODE">0</Property>
<Property name="EXPRESSIONTYPE">0</Property>
<Property name="SCALEDLOW">0.0</Property>
<Property name="VALUE"></Property>
<Property name="OPCITEMPATH">ns=1;s=[TTC_1]N55:$i</Property>
<Property name="ALERTNOTES"></Property>
<Property name="ALERTTIMESTAMPSOURCE">0</Property>
<Property name="ALERTDEADBAND">0.0</Property>
<Property name="CLAMPMODE">0</Property>
<Property name="OPCSERVER">Ignition OPC-UA Server</Property>
<Property name="ALERTACKMODE">1</Property>
<Property name="SCALEMODE">1</Property>
<Property name="ALERTMESSAGE"></Property>
<Property name="EXPRESSION"></Property>
<Property name="ALERTMESSAGESUBJECT"></Property>
<Property name="RAWHIGH">1.0</Property>
<Property name="DEADBAND">0.0</Property>
<Property name="TARGET_NAME">Bot_Setpoint</Property>
</ItemConfig>
I'd like to develop a loop that lets me read the XML, update the variables $t and $i to successive integers defined in the for loop. I'd like to add each iteration of the loop to a single XML output.
In my mind, the (pseudo)code looks something like the following:
[xml]$xml = (Get-Content -Path xmlpath.xml)
$t = 1
for($i = 0; $i -lt 201; $i++){
read xml contents
replace $i in XML with current $i value
replace $t in XML with current $t value
write new XML segment to newfile.xml
$t = $t++}
Am I on the right track?
Thanks in advance, folks.