0

I need to extract usernames from lines similar to this one. The usernames are variable, so I imagine this has to be attacked with regex. (I am clueless about how to pull this off).

<RowGroup>
<RowGroup>
<RowTotal RowNumber="0">USER1</RowTotal>
<RowTotal RowNumber="1">USER2</RowTotal>
<RowTotal RowNumber="2">USER3</RowTotal>
<RowTotal RowNumber="3">USER4</RowTotal>
<RowTotal RowNumber="4">USER 5</RowTotal>
</RowGroup>
</RowGroup>
</RowGroups>
  • if you add `` above the 1st line you will have valid XML. if you load that & coerce it to XML , you can use `$XML_Stuff.RowGroups.RowGroup.RowGroup.RowTotal.'#text'` to get all the user names in an array that can be used elsewhere. – Lee_Dailey Jun 17 '19 at 20:28

1 Answers1

2

See answers for PowerShell and XML like How to iterate through XML in Powershell?

And also look into things like the below code

$data = @'
<RowGroups>
<RowGroup>
<RowGroup>
<RowTotal RowNumber="0">USER1</RowTotal>
<RowTotal RowNumber="1">USER2</RowTotal>
<RowTotal RowNumber="2">USER3</RowTotal>
<RowTotal RowNumber="3">USER4</RowTotal>
<RowTotal RowNumber="4">USER 5</RowTotal>
</RowGroup>
</RowGroup>
</RowGroups>
'@


$xml = [xml]$data

foreach ($row in $xml.RowGroups.RowGroup.RowGroup.RowTotal)
{
    $row.'#text'
}
Kory Gill
  • 6,993
  • 1
  • 25
  • 33