PowerShell Mini-Scripting Games 2014: Problem 2

Summary: Here is Problem 2 in Windows PowerShell Mini-Scripting Games 2014.

Microsoft Scripting Guy, Ed Wilson, is here. It is time for the second problem of the Windows PowerShell Mini-Scripting Games. Remember: Please do not post any answers to these problems until next week. Please do not spoil the fun for your fellow scripters!

Problem 2 description

You have a CSV file that contains five columns. It comes from the HR department and it contains information that you do not need. You only need to work with three of the columns.


  1. Read the CSV file that contains five columns. Create a custom object that contains only columns.
  2. Create a new CSV file (with a different name) that only contains the three columns you selected from Step 1.

Hint: Create a very simple CSV file by using Notepad (or another feature), and save it. The file should contain five columns and several rows of sample data. Keep it simple. The columns CAN be named a, b, c, d, e. Then write code that will read this CSV file, and create an object that contains only three columns from the file. Now save that as a CSV file.

Mini-Scripting Games Week will continue tomorrow when I will reveal Question 3 (PowerTip) and Problem 3.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Comments (4)

  1. COBOL Programmer says:

    I’m guessing it’ll fit on 1 punched card.

  2. Ed Wilson says:

    @COBOL Programmer My mom was a key punch programmer, and I remember seeing the trays of cards. I can tell you for a fact, that it will NOT fit on a single key punch card 🙂 Hope you have fun with the event.

  3. jay says:

    I think there is a word missing for task 1.

    I Guess you meant "Create a custom object that contains only THREE columns."

  4. Rob Simmers says:

    Two steps per the requirments….

    $tooManyColumns = Import-CSV "C:TestTest.csv" | Select a,d,e
    $tooManyColumns | Export-CSV C:testnew.csv

    or the one-liner:

    Import-CSV "C:TestTest.csv" | Select a,d,e | Export-CSV C:testnew.csv

Skip to main content