Managing IIS settings through PowerShell

Do you miss the IISAPP command line tool that was available with IIS6?

Do you feel that APPCMD is not enough?

Enter the WebAdministration PowerShell module!

Its usage is straightforward, as it it leverages the concept of providers and drives that the PowerShell engine uses to unify the way you access resources on your server. And it provides several commandlets that can help you automate most (if not all) of the web administration tasks.

In order to use the WebAdministration module, you need to launch PowerShell with elevated rights, then just import the module:

Import-Module WebAdministration

A quick Get-Command will show you that there’s something to try!

gcm -Module WebAdministration | Measure-Object

In my environment, this shows a total count of 74 items (71 commandlets, 2 aliases and one function).

I’ll let you explore the list of commandlets yourself, while I spend some other words about the function, whose name is “IIS:”.

Just like C:, D: etc, which are indeed just functions that set the current location to the root of the C or D drives, the IIS: function uses the Set-Location commandlet to “move” to the IIS: drive.

Which, of course, is not a drive based on the FileSystem provider, but is relies on the WebAdministration PowerShell provider that you get inside the WebAdministration module.

Thanks to this approach, you can easily “navigate” within IIS settings just by using “dir” or “cd” (which, btw, are aliases too). For examples, if you need to list the IIS Web Sites on the local server, just try with this syntax:

dir IIS:\Sites

Or if you need to get, say, the list of running w3wp.exe processes for a specific application pool, you can type something like this:

dir IIS:\AppPools\<NameOfTheAppPool>\WorkerProcesses

Nice, isn’t it?