"Friends, Romans, countrymen, lend me your ears!" Ok, this isn't a Shakespeare blog but PowerShell continues to be sung from the mountain tops and it's only getting louder. So much so, that I wish I had a nickel for every time I heard the phrase "you can do that easy in PowerShell."
Well, my dad used to say, "Nuthin's easy." However, with a bit of basic PowerShell under your belt, many, many things get easier (note, I didn't say 'easy' J ). By 'things' I mean A LOT of things. AD? Check. Hyper-V? Affirmative. Azure? Ci, senior. Got hotfixes? Indeed. DNS? Uh-huh. DHCP? Yep. You get the point.
So, let's cover some of the basics of PowerShell and get you some One-liners to get you rolling:
Now, I present a fistful of handy PowerShell One-Liners from myself and a few PFE Brothers in Arms (Tom Moser of Ask PFE Plat fame and one Mr. Ashley McGlone, whose own blog is a PowerShell buffet: http://blogs.technet.com/b/ashleymcglone/
Take note in the code how we snuck in a variety of output switches … this is yet another helpful element of PowerShell.
Let's roll …
The server rebooted recently - who did it and when exactly?
Here's a timely post from Ed Wilson about Get-WinEvent: http://blogs.technet.com/b/heyscriptingguy/archive/2014/06/04/data-mine-the-windows-event-log-by-using-powershell-and-xml.aspx
Is there an easy way to see if KB2862152 is installed?
If the patch is installed, you'll get a nice formatted output of where/what/who/when:
Source Description HotFixID InstalledBy InstalledOn
------ ----------- -------- ----------- -----------
DC01 Security Update KB2862152 DC01\User-01 4/22/2014 12:00:00 AM
If the patch isn't installed, you'll get an error stating so:
Get-Hotfix : Cannot find the requested hotfix on the 'WS2012r2-dc01' computer. Verify the input and run the command again.
I need to backup all of the GPOs in the domain every day
What are the IP settings on my system(s)?
What are the BIOS versions on my systems?
A few more …
At this point, you should have noticed some patterns to those One-liners (and to the PowerShell syntax in general). That is one of the key elements that makes PowerShell easier. If you get a handle on how to get event log info out to a CSV file, it isn't much different to get hotfixes, or AD user attributes.
If you have yet to get going with PowerShell, now is as good of a time as any – take 15 minutes each day over the next week (first thing in the morning or after lunch are often good times) and work through these examples. If these one-liners didn't pique your interest, make a list of 5 things you think would be easier with automation and figure out how to do them in PowerShell. Ping us in the comments if you need some help.
If you're still feeling a bit timid, hit up your Technical Account Manager to bring in a PFE for a PowerShell Workshop and we'll get your whole team up to scratch in no time. In the meantime, you can get two days of free PowerShell training at Microsoft Virtual Academy:
Lastly, here's a great reference for PowerShell to wander through and a search-results link for some of our prior AskPFEPlat PowerShell goodness: