The Power of Powershell

In 2001, I got my first actual admin/engineer position. I was working in conjunction with a grizzled old guy who actually had a bumper sticker over his desk that said "I <3 DOS". He was teased relentlessly for it, but while we were clicking around with our little ball-mice on our fancy mouse-pads, he was knocking out in seconds what would take us hours to accomplish. He was the undisputed master of the CLI.

It took me a while to warm up to the idea, but considering one of my first major assignments was "look at all the logs for all the servers every day", I started to see the light. In those days, getting an RPC connection on a flat 10base-T network to 115 servers and then culling through logs in Computer Management took hours. This one task regularly consumed over half of my day.

After talking to him and learning a little bit of VBS, I had the process cut down to 15 minutes (7 minutes when I dumped the WINNT connection method and switched to LDAP).

I spent the next 6 years of my life automating everything I could. We had DOS scripts invoking VB scripts to output text files to serve as feeders to follow-up scripts. It was a glorious Rube Goldberg masterpiece.

But then came Powershell, and the threat that everything I'd just spent all that time learning was obsolete. I refused to admit it for a couple of years (as did he), but one day my boss asked me to run a query against AD to pull back some random minutiae.

A quick check on the Internet told me that I had a decently long day of scripting ahead of me, so I got to work. 5 minutes later, he told me 'never mind, he'd gotten it already'. I fully expected he'd just found somebody's working code and run it blindly against our AD, but he had just used a single Powershell command.

I finally ended up getting my process to run in VBS, but it pulled back less data and took an entire printed page worth of code, and he did it in one command.

Powershell really makes an admin's life easier. Every command (or cmdlet) belongs to a module, and there's a module for just about everything you want to do--AD, Exchange, SQL, System Center, basic host (and remote host!) management, all of it and more. The cmdlets are .NET programs that follow an incredibly simple syntax of verb-noun (get-aduser, set-mailbox, etc) followed, optionally, by switches. Almost every command's output can be piped directly to a follow-up command, making for a very powerful set of one-line administration and reporting.

List of users? Get-aduser -filter *

List of mailboxes on an Exchange server? Get-mailbox

Want specifics on John Doe's mailbox? get-mailbox jdoe | format-list

Need names for all the users in Finance? get-aduser -filter * -properties * | where {$_.department -eq "Finance"} | select name

But if you want to really maximize the benefits of Powershell, you have to get your systems beyond Windows Server 2003. Only Powershell versions 1 and 2 are supported in Windows 2003, but most modules now require version 3 or 4. And Active Directory cmdlets won't even work against a Windows 2003 AD because it lacks AD Web Services.

 

Comments