top of page
Writer's pictureNakkeeran Natarajan

How to read an XML file in PowerShell 2010

In this article we will be seeing how to read an xml file in powershell 2010.

In this we will be creating a simple xml file and we will be reading the xml file in the powershell.

Test.xml

<? Xml version="1.0" encoding="utf-8" ?> <customers>   <Name>Anand</Name>   <Id>123</Id>   <Age>23</Age>   <Location>Bangalore</Location> </customers>

Get the content from the xml file:

[Xml]$xmldata=Get-Content C:\Users\kpast\Desktop\Test.xml


Get all the nodes: $xmldata.customers


Get a particular node: $xmldata.customers. Name

Assign the xml value to a variable:

$variable=$xmldata.customers. Name

Result:

$variable will be equal to Anand.

0 comments

Comments


bottom of page