I have some XML that I want to be able to overwrite the STATUS tag.
how it looks:
<START>
<EXAMPLE>
<THINGS>
<STUFF>
<STATUS>Not_Reviewed</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
<STUFF>
<STATUS>Not_Reviewed</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
<STUFF>
<STATUS>Not_Reviewed</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
<STUFF>
<STATUS>Not_Reviewed</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
<STUFF>
<STATUS>Not_Reviewed</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
<STUFF>
<STATUS>Not_Reviewed</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
</EXAMPLE>
</START>
How I want it to look:
<START>
<EXAMPLE>
<THINGS>
<STUFF>
<STATUS>Open</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
<STUFF>
<STATUS>NA</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
<STUFF>
<STATUS>Closed</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
<STUFF>
<STATUS>Open</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
<STUFF>
<STATUS>Open</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
<STUFF>
<STATUS>NA</STATUS>
<DETAILS>1111 2222 3333 4444 5555 6666 7777 8888</DETAILS>
</STUFF>
</THINGS>
</EXAMPLE>
</START>
With this code I am able to change each of the STATUS tags to the correct value, when I check the console after running just $XMLStatus after the script has run it shows everything as it should, but not when I open the XML in notepad. It still shows everything as Not_Reviewed. I am not sure what I am doing wrong here and any help is greatly appreciated.
[xml]$xmldoc = Get-Content -Path 'C:\test.xml'
$XMLStatus = $xmldoc.START.EXAMPLE.THINGS.STUFF.STATUS
$XMLcount = 0
foreach($one in $XMLStatus[$XMLcount]){
foreach($status in $one){
$one = $myvalue
Switch ($one){
1 {$status = "Open"; break;}
2 {$status = "Closed"; break;}
3 {$status = "NA"; break;}
default {"Open"}
}
$XMLStatus[$XMLcount] = $status
}
}
$xmldoc.Save('C:\test.xml')
$XMLcount++