Drinking the PowerShell Kool-Aid…Repost

This is a reposted blog from my now dead wordpress site so formatting may be poor…

So I’ve recently drank the kool-aid and I’m all in on PowerShell. After TechEd this year and speaking with lots of IT Pros & Industry folks, I knew it was time for me to get up to speed on PS or be left behind.

To this end, I have been working through Learn Windows PowerShell 3 in a Month of Lunches, 2nd Edition by Don Jones and Jeffery Hicks. This IS the place you should start if you are a PS newb like my self, or is the proper term PoSHnewb. Don and Jeff do a remarkable job of teaching PowerShell the way IT Pros work. For the most part, we are not programmers; we’re technicians, administrators , or architects, and that is how we need to use PowerShell; as a tool in which to perform singular or repetitive tasks, mostly from the CLI and sometimes as a script.

I like this book so much that I am having my 4th semester students go through the book to learn PowerShell in a way that will prepare them for the real world. They’ll need the help as I threw a curveball into the usual mix of work for my Windows Server Pro class. Normally, each student completes an individual case study where they build out an SMB windows network in VMs. This semester, I scaled back some of the case study tasks to reduce complexity of the overall network, and now I am requiring them to build the entire Windows Server 2012 network with PowerShell. How crazy is that???? I am doing the project along with them so I can hopefully catch and “gotchas” before they do.

So as I’m working my way through my PowerShell journey, I thought it would be cool to share code examples as they get created. Let me warn you…I can barely script my way out of a paper bag so scripts will be functional but probably could use some streamlining.

In any case, here’s the first useful script I wrote called DumpHistory.ps1. This script is a simple PS script to display and create a text file of all commands executed in the CLI during a specific session. The reason I came up with this was I teach my students to use get-history as a way to see what they have done, as well as keep track of their work. I wanted a way to easily create dumps of my history so I can review them at a later date as well as prep for demos. Again, I am sure someone else has done this, and probably cooler. That’s not the point. For me, it’s about thinking about process I do on a regular basis and seeing if I can create a tool to automate that process to some level.
##Create a text file containing history of PowerShell Commands based on input file name and current date
##Created by Michael Bender
##Created/Revised 10/9/2013
##Create variable for current date
##Get User Input for Name of File
$History=Read-Host “Enter Name for History file”
##Retrieve current CLI history and output to file
Get-History | Out-File C:UsersmikebSkyDriveMatcFall2013ServerProPowerShellhistoryfiles$History.$mo-$dy-$yr.txt

Note: I have the out-file location hard-coded since I use the same location all the time. If you needed to specify the location at each running, the script could be modified by creating a variable for the location with read-host.

A zipped copy of the file is located http://sdrv.ms/1gqqHGe
If you have any suggestions on cleaning this up, please add in the comments.

Till next time…Mike

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax