PowerShell XML Parsing & Export -


i'm new using powershell, , joined stackoverflow. have project @ work try parse xml file , export specific nodes csv file. need *<group>name"unique name"* , member task # exported multiple entries in file exported .csv.

the xml file looks below example several entries group name & associating task #:

<settings><tasks><groups> <group name="some name"> <notes>some notes here</notes> <member t="task">159711687</member> <member t="task">584643293</member> <member t="task">465828474</member> <member t="task">262255905</member> <member t="task">121466829</member> <member t="task">257067112</member> </group>  <group name="some name 2"> <notes>testing</notes> <member t="task">865485927</member> <member t="task">363897901</member> <member t="task">848275733</member> <member t="task">471573148</member> <member t="task">312701058</member> <member t="task">667795378</member> <member>160178363</member> <member>149985003</member> </group> 

so far i've gotten

$xml = [xml] (gc "\\servername\path\to\file.xml") $xml.settings.tasks.groups.group 

i've tried | select member -expandproperty member doesn't return formatting correctly, , not return name either.

i've tried basic | format-list name, member , format-table little results also.

any pointers in right direction newbie helpful.

thanks in advance.

you're headed in right direction. need remember element reference (second line in code) returns array of elements. once have array, need traverse this:

[xml]$xml = gc .\groups.xml $groups = $xml.settings.tasks.groups.group  # $groups array of group elements foreach($i in $groups) {     write-output $i.name         # name attribute each group element     foreach($j in $i.member) {   # $i.member array of member each group element         write-output $j."#text"  # text contained in each member element     } } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -