How to update the specific node of the XML file using PowerShell?

To update the specific XML node using PowerShell, we first need to select that node with the attribute with SelectSingleNode() method.

We have below the XML file from the link stored in SampleXml.XML on C:\Temp location.

In this example, we are going to update Autor and Genre properties of the Book having attribute Id = ‘bk102’

$xml=[xml](Get-Content C:\Temp\SampleXML.xml)


The above commands will load the XML file and select node with attribute value ‘bk102’.

$'Dell James'

The above commands will update the genre and author property.