Powershell on the Way to Work–Part 9

Today is car pool day.   Only problem is somebody at work took that literally and I’m squished in the back seat of a Compact with a “Mr. Turtle” pool.

So I promised to show you one of the cooler Cmdlets I ran into, EXPORT-CSV.

Ok, so what if I told you I could give you a line in Powershell you could run on a staff member’s computer to show just HOW MANY Mp3 files were sitting on their personal folder?

Let’s pick on fictional employee Mary Smith.  Mary’s boss has suspected (Due to the overheating LAN cable behind her computer) that she has been downloading a LOT of MP3’s and storing them on the company workstation.  He like to know just how bad.

So you remember GET-CHILDITEM right?

If we did something like this


That would dump MarySmith’s entire folder to the screen.   That’s neat but useless.    So say we want to filter and only show MarySmith’s massive music collection?

GET-CHILDITEM C:\USERS\MARYSMITH\ –recurse –include *.mp3

As the screen scrolls on by for what seems hours (for you see, MarySmith had a VERY detailed music collection) you realize it would be nice to have report to hand off to her manager to show how detailed the collection is.

Well with Windows Powershell, you can take the output that is going to the screen and pipe it (SEND IT) to another Cmdlet called EXPORT-CSV.   EXPORT-CSV just takes whatever is given to it and “EXPORTS” it to a “Comma Separated Value” file.  Nothing more than that.

So to get all of MarySmith’s detailed collection into a nice sheet that the Boss could navigate in Excel you just run.

GET-CHILDITEM C:\USERS\MARYSMITH\ –recurse –include *.mp3 | EXPORT-CSV C:\Report\MarySmithMp3Collection.CSV

Moments later a nice CSV file perfect for the Spreadsheet of your choice is ready.   The neat thing is you can run just about ANYTHING that is on the screen into EXPORT-CSV.

Of course this was completely fictional.  The real Mary Smith is law abiding citizen.  When you get into Active Directory and Windows Powershell, you could with a MINOR change pull down a userlist or Group Memberships and drop them in as a CSV file.

But that is another story.  We’ll chat later as soon as I get “Mr. Turtle out of my ear”

DSC_0158 (640x425)_thumb

Sean Kearney
Twitter: @energizedtech

Comments (0)

Skip to main content