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.
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.