Overriding Inheritance for IIS 6.0 Virtual Directories

If you have an IIS site that has a mixture of ASP.NET 1.1 and 2.0 virtual directories below it, changing the root site ASP.NET settings could affect the virtual directory ASP.NET settings as well since IIS inherits except for explicit overrides. This little PowerShell script will take each setting and persist it to the virtual directory so you are able to freely change the root site settings without affecting the applications below it.

Please remember to backup your IIS settings before you do this, just incase it has adverse affects on your IIS server.

function Persist-IIsSettings ( $obj ) {
    Write-Host $obj.Path
   
    $obj.Properties.GetEnumerator() |% {
        $propertyName = $_.PropertyName
        $value        = $obj.Get($propertyName)
       
        if ( -not ($value -is [System.__ComObject]) ) {
            $obj.Put($propertyName, $value)
        }
    }
   
    $obj.SetInfo()

    $obj.Children |% { Persist-IIsSettings $_ }
}

Persist-IIsSettings ([ADSI]"IIS://localhost/W3SVC/1/ROOT")

No Comments