This PowerShell Thing May Just Catch On...

I’m just learning PowerShell.  In fact, I’d say I’m just beyond the understanding what’s behind “dir” and “help” (Get-ChildItem and Get-Help).  But even with my limited knowledge I can still do some pretty cool (and time saving) things.

For tomorrow’s Central Ohio Day of .NET I need to collect all the presentations so that I can post them to the website after the event is over.  I did this last year by creating a directory for each speaker on my thumb drive.  This was a little time consuming since I had to do “New -> Folder” for each one.  This year I decided to solve the problem with PowerShell.

I already had a list of the speakers names in a document.  I copied that list into a text file, one on each line.  I then executed the following command from the PowerShell command line:

get-content speakers.txt | % {new-item -path f:\ -type directory -name $_}

Bingo…24 folders created in a flash.  This command is reading each line out of the text file speakers.txt and passing each one as a string object to the next command in the pipeline (the pipe character signifies the pipeline delimiter).  The next command (% is an alias for ForEach-Object) takes each of those strings and executes a New-Item command giving it the path and type of directory.  The $_ is the syntax for the object being passed in form the pipeline. 

In english: Read the text file Speakers.txt and for each line create a directory on the F:\ drive using the text read from the file as the name of the directory.