Reputation: 13
I am trying to fetch an xml attribute value using powershell but not sure how to read the attributes.
Here is my sample xml file with name myfile.xml
<MyFile>
<Parameter name ="internet" enabled ="true" />
</MyFile>
Please suggest me how to fetch the value of attribute enabled using powershell.
Upvotes: 1
Views: 1058
Reputation: 165
Here's a simple solution.
You read from the file, cast it as XML object and then reference properties via dot notation.
$XMLPath = "ENTER_YOUR_FILE_PATH"
# Read the file content, cast it as an XML object and store in variable
$xmlfile = [xml](Get-Content $XMLPath)
# Access particular attribute value
$xmlfile.MyFile.Parameter.enabled
Output
true
Additional methods are listed here.
Upvotes: 1