As a developer I try to use the latest and greatest and when something good comes about I try to pick up as much of it as I can. The use of command or batch files has been a part of my world for a long as I have used computers. Back in the day, there were batch menus for DOS computers so people with little or no computer experience could get the their applications (Lotus 123, Wordstar, etc.) The days of doing DOS menus has past but the power of the command shell remains.
The New Command Shell for Windows
I know I am late to the party when it comes to PowerShell but when it comes to shells I am skeptical at first, excited or dismayed second. Recently there seems to be more and more need to run a shell with more power than VBScript could hope to provide, I was skeptical but I now see the fruit of such a pursuit. When PowerShell hit the street I hardly noticed because I was very happy with my shell and I could do anything with a cscript command that could not be done with old DOS commands. Thanks, but no thanks.
Then something changed, I needed to run a script to start & stop an IIS application pool on another server. I looked and found this http://blog.developers.ie/cgreen/archive/2006/10/20/2341.aspx which clearly uses .NET to control a remote IIS web application pool. I was about to translate this to VBScript when I thought about what PowerShell is supposed to be able to do out of the box. I pursued it and came up with the following script:
# Action : Start, Stop, Recycle param([string]$server, [string]$AppPool, [string]$Action) $sPath = "IIS://" + $server + "/W3SVC/AppPools/" + $AppPool $de = New-Object System.DirectoryServices.DirectoryEntry($sPath) $de.Invoke($Action)
I know it isn’t sexy but it performs the task I needed. This is just the beginning, I’m sure there will be more scripts with more meat in them. Stay tuned, I am starting a series: The PowerShell Journey.