Summary: The Scripting Wife offers her suggestions for completing the PowerShell Scripting Games Beginner Event 3.
Wow. This year, there are nearly twice the number of people competing in the 2012 Scripting Games. There are a few more judges than last year, but the judges are really struggling to keep up. I know that Ed (the Microsoft Scripting Guy) has been up late every night this week grading scripts. He enjoys it, so don’t feel sorry for him.
Instead, feel sorry for me! This event was a bit tricky. It was also pretty hard for me. So here are my suggestions.
1. First of all, the bit about permissions off of the root. I did not worry about. I was able to create my folder there. The thing is this: Create the folder where you have the ability to create the folder. If that is in your Documents folder in your profile, fine. If you have permission on a share, \myshare, then create it there. I asked Ed, and he said you do not have to check for permissions because that would make the event too hard.
2. Check to see if the folder exists. No problem, there is a Windows PowerShell cmdlet that does this automatically. Use the Get-Command cmdlet and look for cmdlets that have a noun of Path. You should be able to figure it out. When you find the cmdlet, look at the Help on the cmdlet and pay attention to the examples. That is it.
3. If the script creates the text file, it should not generate errors that are ignored. This tells me that I need to check for the existence of the file and the folder.
4. I did not do a command-line parameter, and it cost me a point. What I did was have a variable to hold the path to the file, but I did not do a command-line parameter. If you want to get all five points, you should probably do this and pay attention to the Design Points.
5. I did not add comment-based Help because I did not do command-line parameters. So I lost another point here.
6. I saw that someone asked a question about what if the file already exists. The Script Monkey (Ed) said to append to the file… but if you overwrite the file, that would be fine also because he did not specify. Sounds to me like this one is up to you.
Well, I have to go and get ready for the Charlotte PowerShell User Group meeting tonight. We are having a script club. If you are in the area, come out and say Hi. I am sure we will spend a little time talking about the Scripting Games. Oh yeah, Ed will be there too.