Programmatically unlocking IIS configuration sections in Powershell
I wrote a blog post about this quite a while back. http://www.danielrichnak.com/powershell-iis7-teach-yoursel/
The below code will loop through everything in system.webserver level and unlock it. You can target different nodes as you see fit.
$assembly = [System.Reflection.Assembly]::LoadFrom("$env:systemroot\system32\inetsrv\Microsoft.Web.Administration.dll")# helper function to unlock sectiongroupsfunction unlockSectionGroup($group){ foreach ($subGroup in $group.SectionGroups) { unlockSectionGroup($subGroup) } foreach ($section in $group.Sections) { $section.OverrideModeDefault = "Allow" }}# initial work# load ServerManager$mgr = new-object Microsoft.Web.Administration.ServerManager# load appHost config$conf = $mgr.GetApplicationHostConfiguration()# unlock all sections in system.webServerunlockSectionGroup( $conf.RootSectionGroup.SectionGroups["system.webServer"])
Your solution is similar but different enough that I can't verify what you've got, but since you say it works - sounds good. :)