In “Success.txt”, you’ve got a slight bug:
$xx = ($xmlObject | Where-Object {$_.Accounted -eq "DR" -and $_.index="1"}).InnerXml
That second “=” sign ($_.index = “1″) should be another “-eq” operator; don’t mix those up. = is for variable assignments, -eq is for testing equality. You have similar code in pscript.txt which doesn’t have the same bug (both -eq operators are in the right places).
As for pscript.txt, I’m not certain what problem you’re having. I ran it on the sample XML you posted, and it successfully injected the ORIGREF and SUPPINVNUM elements into both PAYLINE elements. It also output some text to the console along the way. Here’s the output that I got:
PS C:\source\Temp> C:\Source\Temp\test.ps1 #text ----- 10080 10104-10 2000 2000 10080 10104-10 2000 2000 C:\source\Temp\test.xml
One thing that may be throwing you off are lines containing the #text header, and 10080 / 10104-10. Those are showing up because the calls to $node.AppendChild($e) return the value of $e (which would allow you to chain together fluent calls). In a PowerShell script, you’d want to suppress that output by using Out-Null, assigning to a variable / $null, or casting to [void] (whatever your preference):
$null = $node.AppendChild($e)
That just leaves the lines containing “2000″. In the sample XML file, each of the two PAYLINE elements has two child elements somewhere in the tree that match your filter, and all 4 of them have an InnerText value of 2000.