PowerShell Rocks!

 

PowerShell has official been released!  Download your copy today!

Of all the new Microsoft technology coming down the pipe, PowerShell has got to be one the most exciting (after IIS7 of course :) ).  You might wonder why am I so excited about the new scripting shell for Windows.  Even if PowerShell is better than Command Prompt on steroids, what does this have to do with my main passion, Web servers and Web applications?    Check out the Channel9 video I did with Jeffrey Snover, architect of PowerShell, to get an idea of how cool PowerShell really is.  In the video we show off a demo we put together for BobMu's keynote in TechEd IT Forum this week, which appears to have gone very, very well.  Well done, Jeffrey. :)

A long long long time ago, when I was in school and even after that, before I came to Microsoft and joined the IIS team, I used to use Linux and spent my days in BASH and ZSH getting work done.   Until now, we sadly never really had the productive power of an interactive shell on Windows.  So as previous heavy-user of shells, I have to tell you what I really like about this new shell interface on its own, then I’ll explain the many ways PowerShell can make work simpler for IIS Administrators.

Ok first off, in PowerShell you input commands on objects not text and PowerShell returns objects and not text, so you can easily pipe commands together in one line.  This allows me to input in just one line, complicated commands like this one,

PS C:\Windows\System32> Get-ChildItem -Path G:\ -Recurse -Include *.mp3 | Where-Object -FilterScript {($_.LastWriteTime -gt "2006-10-01") -and ($_.Name -match "pearl jam")}| Copy -Destination C:\User\bills\Desktop\New_PJ_MP3s

… which recursively looks through the entire my entire external hard drive (G:), collects all of the “Pearl Jam” mp3’s that were recently added and copies them into a folder on my desktop.  Never was I given a text output listing all the mp3’s and I didn’t have to use the Copy command over and over, I just piped the all the items to Copy once.

Another thing I like so much about PowerShell is how consistent PowerShell commands are.   In the example above, I only used one “Get-ChildItem” command but rest assured if I wanted to get anything else, the command for that would start with “Get.”  Similarly, if we want to stop a process or an application or anything, we always use the Stop command, not kill, not terminate, not halt, just stop.

Finally, I love that PowerShell is extensible.  I love this because it means my team can produce a whole set of IIS PowerShell cmdlets to help you manage IIS6, IIS7 and future versions of IIS.  You will also be able to submit your IIS PowerShell scriptlets to this community area (coming very soon J). 

Now that I’ve listed my favorite things about this new shell, I’d like to give you a few ways that PowerShell can and will make IIS administration simpler than ever before.  The top 5…

1.  IIS7 has a new WMI Provider for quickly starting, stopping, creating, removing and configuring sites and applications.  Now use PowerShell, to give a list of applications sorted by a particular configuration setting.  Then pipe apps with the particular setting into the tasks you were performing before with the WMI Provider.  Sergei wrote and just published a fantastic article on how to write PowerShell cmd-lets using our WMI provder, titled Writing PowerShell Command-lets for IIS7.

2.  Because IIS7 has a distributed file-based configuration store, you can store your application’s IIS configurations in a Web.config file in the application’s directory beside its code and content.  Use PowerShell to rapidly XCopy deploy the application to an entire Web farm in one step.

3.  IIS7’s new Web.Administration API allows Admins to write short programs in .NET to programmatically tackle frequent IIS7 management tasks.  Then, since PowerShell completely supports the .NET Framework, use it to pipe IIS objects in and out of these handy bits of code.

4.  With IIS7, you can use the new Runtime Status and Control API to monitor the performance of your Web applications.  Use PowerShell to monitor performance information at a regular interval of every 5 minutes, then have this valuable runtime information displayed to the console or sent to a log file whenever CPU is above 80%.

5.  Take advantage of IIS7’s extensibility by writing your own custom request processing module with its own configuration and IIS Manager plug-in.  Then write a PowerShell cmdlet to serve as a management interface to exposes your custom IIS configuration to the command line and to power your IIS Manager plug-in. 

I could probably list more ways but this post is getting long so I will leave you with links to other good IIS7/PowerShell resources.

· An Introduction to Windows PowerShell and IIS7

· Channel 9 Webcast of Jeffrey Snover and I demoing Powershell managing IIS7

· Windows Powershell on TechNet Script Center

· Windows Powershell Scripting Sweepstakes

· Powershell Team Blog

· Writing PowerShell Command-lets for IIS7

1 Comment

  • I've written two blog posts on how to use and extend the IIS managed SDK within PowerShell.

    Check out:
    Accessing Microsoft.Web.Administration through PowerShell (Part I)
    http://blogs.iis.net/tobintitus/archive/2006/11/30/powershell-and-microsoft-web-administration.aspx

    and
    Extending Microsoft.Web.Administration through PowerShell (Part II)
    http://blogs.iis.net/tobintitus/archive/2006/12/01/more-on-iis-7-administration-with-powershell.aspx

Comments have been disabled for this content.