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.
- Read the CSV file that contains five columns. Create a custom object that contains only columns.
- 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 firstname.lastname@example.org, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy