Wanting to add another child element in system.web element. So far I have tried a number of ways, however, non have worked. I have created this code, which I'm not sure is close or not.
Code so far:
#setting variables
$path = "H:\PSTesting\Logs\ExerciseXml.xml"
$xml = Get-Content $path
#Creating element
$child = $xml.CreateElement("Test")
#setting attributes
$child.SetAttribute('Testing','hey = "something"')
#adding attributes to the location
$xml.'system.web'.AppendChild($child)
#save file
$xml.Save($path)
Below is my XML which needs to be changed. Current:
<?xml version="1.0" encoding="UTF-8"?>
-<configuration>
-<system.web>
<authentication mode="None"/>
<compilation targetFramework="4.5.1" debug="false"/>
<httpRuntime targetFramework="4.5.1"/>
</system.web>
</configuration>
Below is the desired outcome from running the code.
<?xml version="1.0" encoding="UTF-8"?>
-<configuration>
-<system.web>
<authentication mode="None"/>
<compilation targetFramework="4.5.1" debug="false"/>
<httpRuntime targetFramework="4.5.1"/>
<Testing Hey = 'something'>
</system.web>
</configuration>
Any help would be appreciated. Thanks in advance!