Learn about Windows PowerShell
Hey, Scripting Guy! What type of errors and mistakes did you notice in the entries for the 2010 Scripting Games?
-- BA
Hello BA,
Microsoft Scripting Guy Ed Wilson here. I am a really laid back sort of guy, and I do not like the words “errors” and “mistakes.” I prefer to think in terms of opportunities for improvement. There are several themes I have seen as I was reviewing the scripts submitted for the 2010 Scripting Games.
# Now lets get a list of processes Get-Process
# Now lets get a list of processes
Get-Process
BA, these are some of the main things I saw during the 2010 Scripting Games. This brings our 2010 Scripting Games Wrap-Up Week 2 to a close. Come back tomorrow for the Weekend Scripter when we will talk about…wait a minute.
If you want to know exactly what we will be looking at tomorrow, follow us on Twitter or Facebook. If you have any questions, send e-mail to us at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson and Craig Liebendorfer, Scripting Guys
This is a very interesting blogpost. I read a lot of things that I can use to improve my code. One thing that I noticed is that you mentioned the Test-Computer cmdlet. But that doesn't exist. You probably have to change this into the Test-Connection cmdlet.
Great advice, a solid list, but I take issue with one point. The use of the Foreach-Object cmdlet is by far more efficient from a keystrokes perspective, but the Foreach statement IS faster. I would argue that when scripting performance is more important. Hence the use of the Foreach language statement is the best practice. It is not only easier to read a Foreach loop as the variable is named and can be given context (I know what $file is $_ could be anything), but it IS much faster. Unfortunately there are times when using Foreach requires you to breakup you're code, and results in something that is hard to read.... I'm not trying to make a blanket statement. The truth is you should try BOTH, and use what ever works best for you're situation.
Don't get me wrong the pipeline is a fantastic thing, but it can be abused. Another example of this would be using where-object to filter results on a cmdlet that supports filtering (Get-WMIObject,Get-ChildContent,etc)!
I really like the idea of deducting points for reinventing the wheel. Anyways, keep up the great work, look forward to next year!
~Glenn
Great article, as usual, but I DO take issue with one point: "Functions should be organized in the order in which they are called."
My preference, and it is no more than that, is to put functions in alpha order. This way, I can always find them and am not forced to go back and re-arrange entries when I change my logic.
Just a thought...