Mythical IIS Cmdlets

posh-iismod

The bleeding edge is sometimes a few years ahead of the leading edge, so every time I hear about some leading edge technology, I know it’s probably been around for a couple of years if not a few decades. Yes, I know, I’ve been on both of those edges many times before.

Anyway, when I was developing some Windows PowerShell courseware, I kept hearing people talk about the IIS cmdlets, and read about them several places, and knew that since I was supposed to be writing just about PowerShell version 1.0, I couldn’t include more than just a cursory reference about “IIS cmdlets could be written but there aren’t any in production… yet.”

That has changed. In case you’re not running Windows PowerShell version 2.0 with Internet Information Services (IIS) 7.5 on Windows Server 2008 R2 yet, the leading edge is calling you…

Yes, it’s true. Windows Server 2008 R2’s IIS 7.5 does indeed possess these mythical IIS cmdlets after all, and not just a half dozen of them. What can we manage using these IIS PowerShell cmdlets? The shell can tell – try the following command.

 get-command -module WebAdministration | group CommandType

As that command line can tell you, there are 71 IIS cmdlets, 2 aliases, and 1 function. What Get-PSDrive could tell you is that the WebAdministration provider also hosts an IIS PowerShell drive which the aforementioned function changes location to. For the moment, let’s focus on the cmdlets.

get-command -module WebAdministration | group noun | sort Count -desc

 

Grouping the IIS cmdlets by noun and subsequently sorting those groups by the cmdlet count within each group, we can quickly see what kinds of things can be managed using those cmdlets.

Are these cmdlets easier to use than appcmd, or the .NET or WMI interfaces which have been available for several years in PowerShell for managing IIS? That’s a matter of opinion, really. But let’s take a quick glimpse to get you started on being to give an opinion of your own to that question.

Twenty of these cmdlets start with the noun Get, such as Get-Website, Get-WebVirtualDirectory, Get-WebApplication, and Get-WebAppPoolState. Getting information is a good place to start before you start reconfiguring your IIS 7.5 configuration, therefore we’d recommend investigating those cmdlets first. In some cases, these Get-Web* cmdlets require parameters. In other cases, they require some context, such as having previously done a Set-Location (cd) into the a psDrive mapped to the IIS: provider – there’s such a drive already mapped to the local server by default.

There is a lot of power in the IIS cmdlets which deserves investigation. As you try these cmdlets, please feel free to send questions. Perhaps some future posts could come from your questions.

Here are two suggestions on how to launch PowerShell to make sure you have the IIS cmdlets available. Both of these suggestions assume that you have installed IIS 7.5 on your server first, although they can still work in some other scenarios.

Make a shortcut on the desktop to PowerShell, then modify it in one of two ways to get the IIS cmdlets, provider, aliases, and function. Right-click on the Desktop, select New, then Shortcut. Here’s the path to PowerShell to make the shortcut to first:

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe

 

It’s a good idea to name the shortcut something notable like “IIS Shell.” After you’ve made the shortcut, go back and get it’s properties and one of the following to the shortcut’s Target after the “powershell.exe” and a space.

-NoExit -ImportSystemModules

 

When PowerShell is run with the -NoExit -ImportSystemModules parameters, it loads all system modules and the window stays open with an interactive shell.

You might have many modules loaded on your server, such as ActiveDirectory, ADRMS, AppLocker, BestPractices, BitsTransfer, GroupPolicy, PSDiagnostics, ServerManager, TroubleshootingPack, and WebAdministration. If you don’t want to load all of them, but just the WebAdministration module, add the following instead of -NoExit -ImportSystemModules at the end of your shortcut Target.

-NoExit -Command Import-Module WebAdministration

 

In either case, remember the space between the powershell.exe path and the -NoExit parameter. Yes, there should be spaces between the subsequent parameters as well. If you already have a shell open without these modules loaded, you could just use the Import-Module cmdlet inside the shell, as was done within the shortcut mentioned above. At the shell prompt, simply type the following.

Import-Module WebAdministration

 

The question still remains – once you get used to several dozen IIS cmdlets and the provider, will you ever use appcmd.exe again?

Leave a Reply

Your email address will not be published. Required fields are marked *