Mr. Roboto

Get Your Shell On

Automate admin tasks easier with the new Windows PowerShell.

By now you've probably heard about Windows PowerShell -- Microsoft's new automation buddy. If you haven't installed it yet, you really ought to log on to www.microsoft.com/powershell and get rolling.

Now you're probably thinking, "Great. Yet another scripting language to learn." Well, not exactly. Sure, PowerShell has a scripting language, just like the good ol' Cmd.exe shell. The difference is that you're not required to script to make the PowerShell useful. In fact, by default, PowerShell won't even run scripts.

PowerShell is indeed a total replacement for the old Cmd shell. Fire up PowerShell and you can run Dir, Net Share, Copy and all your other favorite command-line utilities. Of course, PowerShell isn't just a replacement for Cmd. It's much better. For example, need to know what Service Pack a particular computer is running? Just run:

Get-WMIObject –class Win32_Operat ingSystem –namespace root\cimv2 –computer DON-PC –property ServicePackMajorVersion

Assuming DON-PC is the computer's name, entering those commands will get you the information you want. Wait a minute -- that's not really any easier, is it? It might seem quicker to use another tool instead of typing all those commands, but this is where PowerShell really starts to shine.

First, you don't need the –class argument name, because –class is the first argument Get-WmiObject takes (just run Help Get-WmiObject to check). The default namespace is already root\Cimv2, so you don't need to specify that. Also, PowerShell supports aliases, which are like nicknames for commands. Run Get-Alias to see them all. Notice that Gwmi is aliased to Get-WmiObject. So now we're down to this:

Gwmi Win32_OperatingSystem –com puter DON-PC –property ServicePackMajorVersion

You get the same result with less typing. But hold on, it gets even better. You only need to type enough of each argument name to distinguish it from any other arguments. Try this:

Gwmi Win32_OperatingSystem –co DON-PC –pr ServicePackMajorVersion

That's much less typing. Want to see what commercial software products are installed on your target machine?

Gwmi Win32_Product –co DON-PC

That's super simple. In fact, all you really need to know is what WMI classes (like Win32_Product and Win32_OperatingSystem) are available for you to use. PowerShell will be happy to list them all. Just run Gwmi –list (just add –computer to check a remote computer's classes).

Of course, if you actually start scripting with PowerShell, you can bundle up even more complex statements, control output formatting and more. You'll see more PowerShell coming your way in future months. Remember: even if you have no interest whatsoever in scripting (despite that being a somewhat shortsighted, career-limiting view these days), PowerShell is an excellent interactive, on-demand tool for Windows administration.

PowerShell's strength isn't limited to just Windows, either. Exchange Server 2007, Systems Center Operations Manager 2007 (the new name for MOM) and most future Windows Server System products will base their entire administrative architecture on PowerShell. That makes PowerShell a one-stop shop for running your entire Windows enterprise.

Need Help?

What Windows admin task would you like to see automated next? Send your suggestions directly to Don at don@sapien.com.

You can also send them to editor@redmondmag.com, just be sure to include Mr. Roboto in the subject line.

About the Author

With more than fifteen years of IT experience, Don Jones is one of the world’s leading experts on the Microsoft business technology platform. He’s the author of more than 35 books, including Windows PowerShell: TFM, Windows Administrator’s Scripting Toolkit, VBScript WMI and ADSI Unleashed, PHP-Nuke Garage, Special Edition Using Commerce Server 2002, Definitive Guide to SQL Server Performance Optimization, and many more. Don is a top-rated and in-demand speaker and serves on the advisory board for TechMentor. He is an accomplished IT journalist with features and monthly columns in Microsoft TechNet Magazine, Redmond Magazine, and on Web sites such as TechTarget and MCPMag.com. Don is also a multiple-year recipient of Microsoft’s prestigious Most Valuable Professional (MVP) Award, and is the Editor-in-Chief for Realtime Publishers.

comments powered by Disqus

Reader Comments:

Tue, Aug 8, 2006 Ernie DeVries Flagstaff, AZ

Powershell sounds interesting and useful, but there is no clue in your article or on the MS web site as to whether it applies to Windows 2000 servers or domains? What versions of Windows server does this apply to?

Add Your Comment Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above

Redmond Tech Watch

Sign up for our newsletter.

I agree to this site's Privacy Policy.