Learn about Windows PowerShell
Summary: Use Windows PowerShell to load an XML file for easy editing.
Hey Scripting Guy! Is there an easy way to load and edit an XML file in Windows PowerShell?
It’s so easy that you might miss it if you blink. Create an XML object. With that, you can load, save, and edit properties directly:
If you do not use full path the load and save will be unreliable. This line is wrong: $XMLfile=load(“MyXMLFile.XML”)
Notice that all comments are stripped of all white space.
Notice also that clicking on "Post" once can post the same message twice. WHITSPACE 5 LINES MORE WHITESPACE
One value in xml is easy, Now lets see you update the an Attribute where there are more than one element of the same type by attribute value. My need comes from an IIS Ap.config layer I need to change the authentication provider on 3 out of 4 sites across
100 web servers. Where that authentication provider is not already set to the correct value.
@jrv You are correct, specifying the explicit path to the XML file is definitely required. It's a finicky Object... Just like Morris the Cat @randy Pitkin If you read the previous post regarding Hyper-V you should see that multiple elements are in fact
updated using this same method, the trick is finding the direct path to access them with XML. Sean
The easy way to load current folder file: $xml=[xml](cat myfile.xml)
The load command is a method of the object so it needs to be $XMLfile.load(“MyXMLFile.XML”) i.e. a dot not an equals