A simple how-to walkthrough of using powershell WebAdministration module for IIS to modify ApplicationHost.config.
Powershell is an excellent tool for running admin tasks on a server. WebAdministration an excellent out of the box powershell snap-in for configuring an mangaing IIS. This provider implements one virtual drive named IIS. It has three logical groupings AppPools,Sites and SslBindings. We can also leverage the capabilities of the built in cmdlets for various operations.
Here we will be modifying “Ftp firewall Support” Data Channel port range settings and Firewall IP settings. Although this particular example is specific to that, these methods can be applied for any applicationHost.config setting.
and this is would show these settings in IIS GUI
By default the “Execution Policy” powershell is “Restricted”. So that means if you just run the import command or WebAdministration, you will get an Exception from powershell. We can set the this policy to “RemoteSigned” that will allow your custom scripts to be run but will not allow any internet downloaded script which is not trusted. We then do this by ruinning the command
PS <path>Set-ExecutionPolicy RemoteSigned
Oouch..you get another error, “access denied”. Did you forgot to run powershell as Administrator? Once you run as Administrator, this will successfully run now. Now import the module, it should be a success again.
Probably the first command you should know would be how to get help, here it is
for getting help about specific commandlets,
PS <path>Get-help <cmdlet name>
to get a list of all supported cmdlets,
PS <path>get-command -pssnapin WebAdministration
more information can be found at http://learn.iis.net/page.aspx/447/managing-iis-with-the-iis-70-powershell-snap-in/