With the release of Windows Server 2012, PowerShell is being pushed as the scripting language that will make command-line...
interfaces the new norm. With over 2,300 cmdlets to choose from, it can ease task automation and free up valuable time for admins.
But what happens when admins run into a PowerShell error? How do you fix it?
Don Jones, PowerShell expert, tackles some common PowerShell errors and explains how to troubleshoot them.
Why won't a PowerShell command run remotely if it runs fine locally?
Remoting can be a great way for admins to have commands run on remote machines. Jones even calls PowerShell's Remoting feature "the way of the future." But Remoting in Windows Server 2012 can come with a few snags.
For more information
Check out the latest version of PowerShell in our PowerShell v3 overview.
There are a few ways to troubleshoot this problem. Confirm that the commands aren't locally contained on the machine you're Remoting to. It's also important to have correct timing as you type the command. Check to see if the command is external and being misinterpreted because of that.
If all else fails, the problem could be the result of what Jones calls an "environmental snag," which has its own steps to troubleshoot.
Why am I unable to compare PowerShell variable contents?
There are a couple of reasons why you might not be able to compare the contents in PowerShell variables. The first is certain PowerShell commands will return more than you want. For example, the Dir command can return multiple objects and multiple types of objects. Another reason is some commands, such as $file, will almost always return multiple types of objects and PowerShell operators, such as –like, can't take on multiple objects.
To solve the problem, write a command that will enumerate the files so you can compare them one at a time. Because you're working with PowerShell, there multiple ways to make this happen.
One way involves a construct (such as Foreach) that will accept multiple objects and then go through them one a time. Another way involves a command-line technique instead of a scripting-style technique.
Why does PowerShell show an error when I try to access a file?
If you keep getting a problem while trying to access a file, part of the problem can come from the way you're telling PowerShell to access that file. One of the most important things to remember with this problem is that the majority of PowerShell commands produce objects as their output and that a command's input parameters might not accept entire objects.
To troubleshoot this problem, be sure to check that the properties in your command variables and the data they contain are what you really need. For example, with $file, would something like Fullname provide the path you need to the files? Or would concatenation for some form of Name and Path suffice?
In the end, you may actually need just one or two properties in a command to get you what you're looking for.
Dig Deeper on Windows PowerShell Scripting
Related Q&A from Toni Boger
Clustering in Windows went through major change with the Windows Server 2012 release. Here's what's new and how to take advantage of the improvements.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.