Powershell and Me
My first post is going to be about Powershell, which I have grown to absolutely adore over the past few months.
I've been a computer network administrator for 4 years now, and most of my previous experience with scripting languages and command-line interfaces has been confined to VBScript and the DOS/Windows command line. While I am quite comfortable with writing batch files, I have done my very best to avoid using VBScript except in absolute necessity. For that matter, my cohort knows VBScript well enough, so I can lean on him if I need anything scripted. Throughout the implementation of Windows Server 2008 and the R2 follow-up, as well as Exchange 2010, Lync 2010, and a small Sharepoint 2010 deployment, I have been able to get by with looking up needed Powershell commands online and pasting them in with slight modifications to accomplish what I needed to.
Microsoft released the Windows Server 8 Developer's Preview several months ago, and it became apparent to me that Powershell was going to be more and more important in my day to day management of Windows Servers moving forward. I suppose I already knew that this was true before the Server 8 release, but using the developer's preview made something internally tell me, "Self, you had better get to learning this Powershell stuff." And so I did. I will spare you a "How to Get Started with Powershell" blog post, because brighter minds have already done the topic far better justice than I could. I will, however, lay out a list.
Top Ten Powershell Command for Noobs -- This list is in no particular order!
- Get-Help -- Use this command to research Powershell related topics and to get help with how to use commands. I use it quite a bit to find out what the syntax is for a command.
- Get-ChildItem -- This is the equivalent of 'dir' in DOS. It returns the contents of a directory. This command was useful as a benign command I could play with without damaging anything while exploring other concepts like piping and switches.
- Get-Command -- This command allows you to find other commands. For example, 'get-command get*' will return a list of all of the Powershell commands that begin with 'get'.
- Get-Member -- Piping the results of one command into Get-Member will let you see what's possible with the object that was returned. For example, 'get-childitem | get-member' will return a list of properties (things you can see or sort by) and methods (things you can do) for a directory listing object.
- Get-Alias -- This shows you all of the aliases. For example, Powershell treats the command 'dir' as if it was running 'Get-ChildItem'. Aliases save massive amounts of typing.
- Get-History -- This brings up a list of the last 10 commands you entered. Each command has its own ID number. Another handy shortcut is that if I wanted to run the command with ID number 2 again, I could type 'r 2' and it would run the command again.
- Get-PSDrive -- shows you a list of all of your Powershell drives. Sure, all of your filesystems show up, but you might be surprised to learn that Powershell loads many other things as accessible 'drives'. Most notably for me was that I could browse the HKCU and HKLM registry hives as a hierarchy!
- Where-Object -- Use this command after a pipe to set criteria on what you want to see, such as filenames with a certain extension.
- Sort-Object -- Use this command after a pipe to sort object based on criteria you choose. Note that some commands have a sort switch to handle this built in.
- Select-Object -- Use this command after a pipe to specify which properties of an object you wish to see. ProTip: Use get-member to see what properties are available!
get-childitem -filter *.mp3 -recurse | select name > mp3s.txt
I would like to plug an EXTREMELY useful book I've been using to learn Powershell called Windows Powershell in Action by Bruce Payette. You can find the book at Bruce Payette's website.
In my next post I'll talk about some extremely useful Snap-Ins and Modules that will make Powershell administration really come alive!