How to automate or script the configuration of IIS 7.5 REQUEST FILTERING for a site

How can I script the "Request Filtering" in IIS 7.5?

I would like a way to ensure that the file extensions are all the same across all 4 of our IIS servers. The way I do this manually now is:
* Open IIS manager
* Select the site
* find the "Request Filtering" icon
* Click "open feature"

Once I am in the feature, I can remove extensions and add them. How can I create a script that will allow me to push these settings to all 4 of my web servers to make sure they stay the same across all servers all the time. I have attached a screen with the extensions screen I am speaking of. I have all the extensions in a text file. I just need a pointer to a good web article or powershell command that would allow me to manage this via script not GUI.

Thanks experts!
sqlagent007Technology professionalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael B. SmithManaging ConsultantCommented:
You can embed the necessary commands into a PowerShell script on Server 2008 R2, if you want; but to the best of my knowledge native PowerShell cmdlets are not available.

This serverfault posting shows you how to do it with appcmd.exe:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The native cmdlets to use here would be Set/Get/Add-WebConfiguration
In your case, for a defined set of allowed extensions, you'd use Set-, which eradicates everything that was there before.
All you need is the PSPath to the site and the list of extensions:
$sitePath = 'IIS:\Sites\Default Web Site\RequestFilteringTest'
$allowedExtensions = Get-Content -Path 'C:\Temp\Extensions.txt'

Import-Module WebAdministration
$values = $allowedExtensions | ForEach-Object {@{fileExtension=$_; allowed='true'}}
Set-WebConfiguration -PSPath $sitePath -Filter 'system.webserver/security/requestFiltering/fileExtensions' -Value $values

Open in new window

Michael B. SmithManaging ConsultantCommented:
Hmmm. I don't have WebAdministration on my IIS 7.5 server. Perhaps because I did a B2B upgrade to get there? I dunno, it's too old a version of OS to worry much about. But it appears to just be a wrapper around appcmd.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Went deep down into the dusty archives and tested on a plain Server 2008 R2 with PS 2.0 (actually has PS 3.0 installed, but the module works in 2.0 as well); no additional PS modules installed.
PS C:\> (gwmi Win32_OperatingSystem).Version
PS C:\> $PSVersionTable.PSVersion.ToString()
PS C:\> (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\InetStp).VersionString
Version 7.5
PS C:\> ipmo WebAdministration -PassThru | fl

Name              : WebAdministration
Path              : C:\Windows\system32\WindowsPowerShell\v1.0\Modules\WebAdministration\WebAdministration.psd1
Description       :
ModuleType        : Manifest
Version           :
NestedModules     : {Microsoft.IIS.PowerShell.Provider}
ExportedFunctions : IIS:
ExportedCmdlets   : {Add-WebConfiguration, Add-WebConfigurationLock, Add-WebConfigurationProperty, Backup-WebConfiguration...}
ExportedVariables : {}
ExportedAliases   : {Begin-WebCommitDelay, End-WebCommitDelay}

PS C:\> Get-WebConfiguration -PSPath 'IIS:\Sites\Default Web Site' -Filter 'system.webserver/security/requestFiltering/fileExtensions'

allowUnlisted         : True
applyToWebDAV         : True
Collection            : {Microsoft.IIs.PowerShell.Framework.ConfigurationElement, Microsoft.IIs.PowerShell.Framework.Co
                        nfigurationElement, Microsoft.IIs.PowerShell.Framework.ConfigurationElement, Microsoft.IIs.Powe
PSPath                : MACHINE/WEBROOT/APPHOST/Default Web Site
Location              :
ConfigurationPathType : Location
ItemXPath             : /system.webServer/security/requestFiltering/fileExtensions
Attributes            : {allowUnlisted, applyToWebDAV}
ChildElements         : {}
ElementTagName        : fileExtensions
Methods               :
Schema                : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema

Open in new window

Michael B. SmithManaging ConsultantCommented:
I believed you. :-)
For my own peace of mind
sqlagent007Technology professionalAuthor Commented:
Hoping I can split points here, both of you have been so helpful! Thank you! I ended up using appcmd.exe as that seems to work across all W2008 servers (yes, the are being donated to a museum). However I am rapidly trying to lear PoSh, so the input from oBdA was also very helpful. Thanks again!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.