I have a Powershell script that I'm trying to write to go thru a poorly formatted XML file to look for any nodes that have the word "Date" as part of the node name. I.E.
<System><SystemName>Acme</Systemname><SystemDate>313</SystemDate><SystemNumber>3</SystemNumber><FileDate>394</FileDate></System>
The above pattern is repeated with hundreds of times thoughout the file... for about 70MB worth of data.
The real file has lots more nodes and no linefeeds or anything... so it all appears on one line.
What I need to do is scan the file and look for any nodes that end in "Date" where the value is not 4 digits and replace with a 4 digit value.
Here is what I have so far... but it looks like the replace is only changing the first occurance and not all other matches after the first match.
Using the example above, it should find the closing </SystemDate> and closing </FileDate> node and see that the digit is only 3 characters and replace with 9999.
$infile=get-content z:\system.txt
write-host $infile.Length
$regex = New-Object System.Text.RegularExpressions.Regex ">\d\d\d</(.*Date)"
$replace = $regex.Replace($infile,"9999")
write-host $infile.Length
write-host $replace.Length
set-content -Value $replace z:\new_system.txt
Any help would be appreciated!