Hi all
I have a problem and I’m hoping there is a solution using PowerShell. I have a group of IIS 7 web servers, and somehow the handler mappings are not set to inherit their settings from the parent. This means that the applicationhost.config file is huge, because every application in every website lists every handler individually.
I could go through each one and select ‘Revert to parent’ in IIS, but this would take ages. Similarly I could delete the handlers node for each application from applicationhost.config, but again this would take a long time.
After some reading around I found I can view the handler data for each site and application with these commands
Get-WebConfigurationProperty -filter system.webserver/handlers/add -PSPath ‘IIS:\Sites\Site_Name\Application_Name’-name allowpathinfo
Get-WebConfigurationProperty -filter system.webserver/handlers/add -PSPath ‘IIS:\Sites\Site_Name\Application_Name’-name name
Get-WebConfigurationProperty -filter system.webserver/handlers/add -PSPath ‘IIS:\Sites\Site_Name\Application_Name’-name modules
I can change these values using set-WebConfigurationProperty, but that doesn’t really help me. I need a command that will delete the handler node, or revert it to parent.
I started working on a script, but this is all I’ve got so far…
$IISObject = gci iis:\sites -recurse | where { $.NodeType -eq “directory” -or $.NodeType -eq “application” }
foreach ( $object in $IISObject )
{
#At this point I think I need something like this:
$handler = Get-WebConfigurationProperty -filter system.webserver/handlers/add -PSPath ‘$Object’ -name allowpathinfo
$handler.delete
#but I know it won’t work because I’m guessing. Can anyone offer any tips?