I’m relatively new to PowerShell and I'm having issues creating a script to modify and save an XML file (web.config) using PowerShell. The Structure of the XML file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Password" value="Test1234" />
</appSettings>
</configuration>
I have tried numerous approaches on trying to get powershell to edit the Password Value and save it again but non are working. My latest being:
$webConfig = "Z:\TEMP\Web.config"
$doc = new-object System.Xml.XmlDocument
$doc.Load($webConfig)
$doc.get_DocumentElement()."appSettings".WebAdminPassword.value = "$Password"
$doc.Save($webConfig)
the variable $Password is a Random 15 character password being generate earlier in the script. Can anyone advise where im going wrong? Thanks!