Chapter 27. Ten Common PowerShell Mistakes
In This Chapter
Not allowing scripts to execute
Improperly using commas to separate parameters when calling a function
Not defining functions before using them
Forgetting that pipelines pass objects and not just strings
Not casting variables as a string
Making incorrect comparisons
Expending the pipeline to far
Not taking variable scope in account
Debugging without the debugger
Forgetting to use available .NET classes
Everyone makes mistakes! There's no shame in that fact, especially when you're trying to get your arms around a new scripting language. In this chapter, I talk about some typical mistakes that new Windows PowerShell users make and how you can avoid them.
Forgetting to Change the Execution Policy
The default installation security of Windows PowerShell is one of the first things that newcomers to the language run into when they try to play around with Windows PowerShell on their own. You go online, find a few commands that you like, and try them; they work great. Then you find someone who wrote a script that does exactly what you want. You've read enough to know that the script should be saved with a .ps1
file extension, and when you try to run it, you inevitably run into the exception that prevents anyone from running scripts due to the execution policy.
If you intend to run Windows PowerShell scripts, you must either digitally sign your scripts (as I discuss in Chapter 21) or not require local scripts to be signed by setting the execution ...
Get Windows PowerShell™ 2 For Dummies® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.