Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Select Xml node attribute

$
0
0

Hi,

i have the below XML <?xml version="1.0" encoding="utf-8" ?>
<Locations>
  <Location>
    <PreRequisites DownloadPath="DP1" LocalPath=""/>
    <Software DownloadPath ="" LocalPath="">
    </Software>
  </Location>

  <Location>
    <PreRequisites DownloadPath="DP2" LocalPath=""/>
    <Software DownloadPath ="" LocalPath="">
    </Software>
  </Location>
</Locations>

I am trying to loop it and assign each location xml values to variables. But i could not get the value of attributes like DownloadPath.

Below is the script i am testing to fetch the value

 

[xml]$ConfigFile = Get-Content "$MyDir\Myxml.xml"

try
{

   #$ConfigFile.Configurations.Configuration.PreRequisites.DownloadPath
   foreach($config in $ConfigFile.Locations.Location){
       write-Host $config.PreRequisites | Select DownloadPath
      
      
}
  
}
catch
{
   Write-Warning $_.Exception.Message
}


Viewing all articles
Browse latest Browse all 6937

Trending Articles