Reputation: 5482
I have an xml file like given below
<ParentNode>
<childnode1>
<Name string="Code1"/>
</childnode1>
<childnode2>
<Name string="Code2"/>
</childnode2>
<childnode3>
<Name string="Code3"/>
</childnode3>
</ParentNode>
how can i print all the child nodes of ParentNode using powershell
i tried by using given code
foreach($child in $xmlfile.ParentNode)
{
Write-Host $child
}
it should print
childnode1
childnode2
childnode3
Upvotes: 2
Views: 205
Reputation: 26120
PS>[xml]$x=gc c:\temp\xml.xml
PS>$x.ParentNode
or maybe you want :
PS>$x.ParentNode |gm -MemberType property |select -expand name
childnode1
childnode2
childnode3
Upvotes: 1