The 5 ways in which PowerShell can be used to make your work easier

PowerShell PowerShell PowerShell… It’s everywhere! You can’t read up on anything in Microsoft (or elsewhere) where it doesn’t talk about how PowerShell is a major part of the subject and yet, there are still lots of admins and engineers out there not using PowerShell. One response I got as to why this is the case was “My way still works, why should I change?” This response will probably come from someone who thinks the cloud is just a fad (Hint: It is not a fad).

I thought I would give a synopsis of the different ways in which you can use PowerShell.

#1 Automation

This you’ve probably heard, but it always bears repeating. PowerShell is an automation machine. Not only is it an automation machine, it does automation faster, easier and cleaner than anything previous (Sorry VBScripters… it true). Scripts I wrote in VBScript years ago I’ve since recreated in PowerShell in less than half the amount of lines. Of course you realize less code = less errors = less time spent working on those scripts. If you are not automating with PowerShell, you’re working too hard.

#2 Gathering Information

PowerShell is a fantastic tool for gathering information. Not only will it gather that information from multiple sources, it will put it all together and output it any way you want all with more than a single line of code. Your boss wants to work on something he or she things will be a huge undertaking? Gather the information with PowerShell and let your boss know it will or won’t be a huge undertaking in a few minutes. How many users have never logged on? How many Group Policies are not linked anywhere? How many Exchange mailboxes aren’t being used? Find this information easily with PowerShell. I don’t think your GUI will tell you this stuff.

#3 Reactive

Something just broke and it’s your job to find out what it was. I have a collection of little functions I call from a “Parent” function any time something goes wrong in my Exchange environment. It checks disk space, mail queues, running services to name a few. When someone comes into my office with a problem, the first thing I do is run my script. Any red flags are checked on and in some cases we’ve gotten back up an running in no time. As issues (and their resolutions) come up, I add it to my script. PowerShell is a building process you don’t have to have all the answers day 1. As you build your library, your downtime will shrink and everyone likes that.

#4 Proactive

Before anything goes wrong, before the red phone rings, be proactive with PowerShell. You can easily setup PowerShell to check your event logs on a nightly bases and send you (or your team) an email summary of events which may be of concern. Got System Center running? Add a PowerShell script which gathers get-process information when the Operations Manager says the system is out of memory (ok, that might be reactive, but getting that little bit of info in System Center is proactive). Found a recurring problem write a script to check things on a regular interval. DSC anyone?

#5 PowerShell working for PowerShell

This is the BEST! This is breaking down the fourth wall of PowerShell! This is where you make PowerShell REALLY work for you and itself. Here is an example: A while back I needed to write a script which would run on a nightly bases and make regular changes to hundreds of groups. I won’t go into details, but think of it as we gave instructions to hundreds of admins and this was our insurance policy that things were done right. Anyway, I’m working on the script, I add copious amounts of logging. One log for changes made, one for errors that occurred and one super verbose for me in case I needed to make a change. At the time there was potential that the changes this script would make would break user’s functionality. I started to think about that. What I did was when it came time to make the change, and the change was successful, I also wrote a command to a script file which reversed the change. Not only was I reactively automating the change, I was proactively writing the script which would reverse the change if there was ever a problem!

Here is another way PowerShell can make your life easier… I often need to gather messaging logs from Exchange. To do this, with a certain amount of specificity, I need to write a single line of PowerShell which is generally fairly long. It’s not much use to write a function for it because calling the function wouldn’t be much shorter than the original. So, I wrote an “Example module.” A module where I call various commands to get *My* examples for commands. All these functions do is write to the screen (color coordinated of course) my examples. All I need to do then is copy the one most like what I need, paste at the command line and make a few changes.

Windows PowerShell for Developers

There are dozens of other ways you can get PowerShell to work for you. Get “Windows PowerShell for Developers” by Douglas Finke (Microsoft MVP) if you really want to get an idea of the kinds of things you can do to make PowerShell work for you.

PowerShell is really an amazing tool. Its versatility lends itself to great creativity.

For those who haven’t started with PowerShell, don’t feel overwhelmed. PowerShell (like ANY language) is a building process. Don’t wory, you’ll get there and you will be so happy when you do.

If you know of other ways in which PowerShell can be used, I’d love to hear them.

Thanks for reading

Leave a Reply