Welcome to TechNet Blogs Sign in | Join | Help

PFE Ireland

Welcome to the Irish Premier Field Engineering blog
PowerShell – Read an XML configuration file

I was recently asked a question about PowerShells ability to read in an XML configuration file at a Virtual Academy I ran last week.  One of the strengths of PowerShell is its ability to perform lots of time saving tasks … one of which is reading in an XML file.  The Get-Content command can read in an XML file and you can easily loop through the contents.

Example:

[xml]$computerlist = Get-Content computers.xml
foreach( $computer in $computerlist.computers.target) 
{ 
    Write-Host $computer.name
} 

What would the XML file look like?

<computers> 
  <target> 
    <Name>server1</Name> 
  </target> 
  <target> 
    <Name>server2</Name> 
  </target> 
</computers>

Nice and simple really.

 
Posted: Tuesday, October 27, 2009 12:44 PM by gmcshera
Filed under: , ,

Comments

No Comments

Anonymous comments are disabled
Page view tracker