I would like to add <logFile directory="D:\Logs\HTTP\example1" /> to each of the site element if it doesn't have it. I have already created a scrip but it doesn't seem to be recognizing the CreateElement method on a foreach object in the xml file it only has .SetAttribute and SetAttributeNode.
$path = "I:\Projects\applicationHostBackUp.config"
$xpath = "/configuration/system.applicationHost/sites/site"
$selector = Select-Xml -Path $path -XPath $xpath | Select-Object -ExpandProperty Node
foreach($object in $selector) {
if($object -match $object.logFile) {
}
}
<configuration>
<system.applicationHost>
<sites>
<site name="AppExample" id="3" serverAutoStart="true">
<application path="/" applicationPool="exampleApp">
<virtualDirectory path="/" physicalPath="F:\Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="241" />
</bindings>
<logFile directory="D:\Logs\HTTP\exampleApp" />
</site>
<site name="AppExample2" id="51" serverAutoStart="true">
<application path="/" applicationPool="exampleApp2">
<virtualDirectory path="/" physicalPath="F:\Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="241" />
</bindings>
</site>
<site name="AppExample3" id="521" serverAutoStart="true">
<application path="/" applicationPool="exampleApp3">
<virtualDirectory path="/" physicalPath="F:\Web" />
</application>
<bindings>
<binding protocol="http" bindingInformation="241" />
</bindings>
</site>
</sites>
</system.applicationHost>
</configuration>