mikeydk
asked on
Group-Object on XML (Text)
Hey
XML:
Powershell:
How do I Group-object on sso (#text value)?
XML:
<?xml version="1.0" encoding="utf-8"?>
<Company>
<employee id="1">
<sso suppId="0">1234</sso>
<firstName>Bob</firstName>
</employee>
<employee id="2">
<sso suppId="0">2222</sso>
<firstName>Andy</firstName>
</employee>
<employee id="3">
<sso suppId="0">1234</sso>
<firstName>Bob</firstName>
</employee>
</Company>
Powershell:
$xml = [xml] (Get-Content ("Demo.xml") -Encoding UTF8)
$xml.company.employee | Group-Object -Property firstName #Working
$xml.company.employee | Group-Object -Property sso #Not working
How do I Group-object on sso (#text value)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Seems to me you solved your own issue :)
This works
This works
$xml.company.employee | Group-Object -Property { $_.sso.'#text' }
Yet another way to skin the cat as it were..
Coralon
$xml = [xml]::new()
$xml.load('d:\temp\test.xml')
PS C:\temp> $xml.Company.employee | Group-Object -Property {$_.sso.innertext }
Count Name Group
----- ---- -----
2 1234 {employee, employee}
1 2222 {employee}
Coralon
@Mikey
Is this problem resolved? If so, it is time to close the question
Is this problem resolved? If so, it is time to close the question
ASKER
$xml.company.employee | Group-Object -Property { $_.sso.'#text' }