Question:
One of my application is generating below XML file.
1 2 3 4 5 6 7 8 9 10 11 |
I am interested in reading the value and errorcodes of “PWR.WakeupOnLAN” property name. Before posting here, I tried various things but couldn’t find correct code for reading properties in powershell. Can any one help me with powershell code for this?
Answer:
In PowerShell 2.0 you can solve this using the new Select-Xml cmdlet and an XPath expression:
1 2 3 4 5 |
[xml]$document = " $value = (Select-Xml -Xpath "//property[@name='PWR.WakeupOnLAN']/@value" $document).Node.Value $errorCode = (Select-Xml -Xpath "//property[@name='PWR.WakeupOnLAN']/@errorcode" $document).Node.Value |
Related resources: