Share via


Getting XML values in PowerShell

I couldn't believe how easy this was when I finally figured it out... I needed to enumerate all of the email addresses with an <email> tag in an XML file. The only really tricky thing was using the "InnerXML" property

 # Create XML document from file
$MemberDoc = [xml](get-content $XMLFile)

# Get all of the email addresses in the XML document
$EmailAddresses = $MemberDoc.GetElementsByTagName("Email")

Foreach ($Email in $EmailAddresses){

 # Get InnerXML value of Email node and assign it to string
 $stmail=$Email.InnerXML

}