Brent Saltzman


Interested in all things technology with a passion for analog, design, audio, and anything that sparks creativity and imagination.


Using PowerShell to update XML files on remote computers

Someday you might need to update XML configuration files for an application on a remote computer or many remote computers. In my case I had to do this, stop, and start a system service on 87 computers.
Here's how I did this using PowerShell:

The great thing about this script is that it takes the remote PC's hostname via an argument in the PowerShell command line like this:
C:\scripts> .\editXML.ps1 Remote-PC

This allows you to execute the script over and over for different hostnames or use additonal scripting to pass in rows from a CSV file for additional automation.

The hostname command line argument is required so without specifiying a hostname the script will not run. You will need to update the $path variable to the path of the XML file and update the xpath of the values you would like to change. You can use regular xpath notation and simply replace the / with . such as /xpath/to/node/value to xpath.to.node.value. It's surprisingly very easy to work with XML in PowerShell.
For more info on working with system services in PowerShell see here and here.

One last note: In order for this script to work properly it must be executed under a user account that has administrative privileges on the remote computer(s).
You also might need to set the execution policy of PowerShell before it will be allowed to run.
See this TechNet article for more information about execution polices

Previous Post | Next Post