Link to home
Start Free TrialLog in
Avatar of mikeydk
mikeydkFlag for Denmark

asked on

Group-Object on XML (Text)

Hey

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>

Open in new window


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

Open in new window


How do I Group-object on sso (#text value)?
Avatar of mikeydk
mikeydk
Flag of Denmark image

ASKER

Seems to be:

$xml.company.employee | Group-Object -Property { $_.sso.'#text' }
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Seems to me you solved your own issue :)

This works
$xml.company.employee | Group-Object -Property { $_.sso.'#text' } 

Open in new window

Yet another way to skin the cat as it were..

$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}    

Open in new window

                                                                                     

Coralon
@Mikey

Is this problem resolved?  If so, it is time to close the question