Printing XmlElement names in PowerShell Printing XmlElement names in PowerShell xml xml

Printing XmlElement names in PowerShell


You can do something like this:

$xml.Root | gm -MemberType property | select Name


You could use the LocalName property instead as you're not using namespaces with your XML:

$xml.Root.ChildNodes | foreach { $_.LocalName }


While manoljlds solution works for getting all element names of children in a parent node, it doesn't help for single elements or when you want to use the element name with the element. I ended up just using Reflection.

$xml.Root.ChildNodes | % { $_.GetType().GetProperty("Name").GetValue($_, $null); }