Top Ten: PowerShell AnnoyancesTop Ten: PowerShell Annoyances
Learn to overcome some of PowerShell's confusing features
August 18, 2012
After leaving Windows PowerShell on the shelf for a few months, I recently had to rework some of my existing scripts for some benchmark tests I was performing for one of our product reviews. I've always been a fan of PowerShell, but in the process of working with these scripts, I couldn't help but notice (i.e., be annoyed by) some of the different PowerShell "features" that are certain to confuse administrators and others who are trying to learn PowerShell. I'm aware that there are reasons for all of these different features. However, they're almost all hurdles to learning PowerShell, and many could make people throw up their hands and give up, which would be unfortunate because PowerShell is on the verge of becoming a necessary tool for the Windows administrator. In this column, I'll share the top 10 things that annoy me about PowerShell.
1. Positioning PowerShell as an interactive command console—Maybe it's because I jump in and out of PowerShell according to the tasks I want to accomplish, but I almost never use PowerShell straight from the PowerShell command line. Microsoft uses automation and productivity to sell PowerShell, and you don't get those things by attempting to type in a bunch of complex text commands. You get automation and productivity by running scripts that automate repetitive tasks.
2. Default execution policy prevents scripts from running—I realize this feature is there to secure your scripts, but there's no doubt that just about every PowerShell newbie is going to run into the default Restricted execution policy right out of the gate, which prevents scripts from running. And you'll probably hit this problem again on each and every new system where you want to run your scripts. Remember, if you want to run a script, you first need to run Set-ExecutionPolicy RemoteSigned or Set-ExecutionPolicy Unrestricted.
3. Not being able to run PowerShell scripts from the command line—No wonder Microsoft likes to promote PowerShell as an interactive environment. Even in the PowerShell environment, you can't run a script just by using its name. From the Windows Command Shell, you can't run a PowerShell script just by entering its name at the command prompt. If you're running a Windows Shell, you need to use powershell -noexit "& "C:usersmikeomy scriptPSscript.ps1" to launch a script, which leads directly to my next annoyance.
4. Calling PowerShell scripts—It's not enough that you can't start a PowerShell script by typing its name. You can’t even easily start it by passing it as a parameter to the powershell.exe executable if the path name has any spaces in it. Instead, you have to add the call operator, &. Adding the & isn't exactly intuitive, and it's definitely a hurdle for beginners.
5. Not being able to run scripts out of the current directory without an explicit reference—Another annoyance occurs when you attempt to launch scripts out of the current directory. Unlike the friendlier Windows Command Shell, PowerShell doesn't load commands from the current directory by default. You must either explicitly supply the path, which is a tedious and error-prone process with today’s long path names, or you can use the . notation, for example: ".
About the Author
You May Also Like