How to parse a XML file and get the Node value using Powershell


Let us say that we have sample XMl file like this

<?xml version="1.0" encoding="utf-8"?>
  <body>Hello World!</body>

The following will read the file and get us the value of the nodes

$path= "C:\Sample.xml"
$oXMLDocument=New-Object System.XML.XMLDocument 
write-host "Value to To:" $
write-host "Value to From:"$oXMLDocument.note.from
write-host "Value to Heading:"$oXMLDocument.note.heading
write-host "Value to Body:"$oXMLDocument.note.body

This is easy but when i had a do this and checked how it took me lot of time to come to this.

So thought of sharing

Hope it will be helpful

Sudheesh Narayanaswamy


This posting /Script  is provided "AS IS" with no warranties and confers no rights

Comments (0)

Skip to main content