Extending Microsoft.Web.Administration through PowerShell (Part II)
In my previous post, I showed you how easy it was to leverage your knowledge of the IIS 7 managed SDK in Windows PowerShell. We loaded the IIS 7 managed assemblies and then traversed the object model to display site information and stop application pools. While this in itself was pretty cool, I don't think I quite got my point across about how powerful IIS 7 and PowerShell are together. As such, I wanted to show you some more fun things to do with PowerShell in the name of easy IIS 7 administration.
First, our examples still required a great deal of typing and piping and filtering. Let's modify our profile script from my previous post by adding at least one new global variable that will give us access to the ServerManager without much typing. Add the following line to your profile script from my previous post.
new-variable iismgr -value (New-Object Microsoft.Web.Administration.ServerManager) -scope "global"
(if you don't have a profile script yet, go back to my previous post to learn how to create one).
Note: If you signed your script before, you'll have to do it again after modifying the script
Open a new instance of PowerShell and now you can access the site collection just by typing:
PS C:\> $iismgr.Sites
That's considerably smaller than our previous examples. But let's not stop there. What happens if I want to search the site collection? PowerShell has some fun syntax for this as well. I simply pipe the output of my SiteCollection to a "Where-Object" cmdlet and then specify what site I'm looking for:
$iismgr.Sites | Where-Object {$_.Name -match "Default*"}
( blog post continued on IIS.NET ... )