Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Powershell.exe troubles with spaces, quotes, and arguments

67 views
Skip to first unread message

winnt

unread,
Nov 20, 2009, 4:55:01 PM11/20/09
to
I need to run a PowerShell script from a command prompt, but am having
trouble. This command works fine inside PowerShell:

Get-WMIObject MSCluster_ResourceGroup -ComputerName MYEXCHANGE01 -Namespace
root\mscluster -filter "name='Cluster Group'" | Format-Table __Server

When I launch it from a command line:

powershell.exe -psconsolefile "D:\Program Files\Microsoft\Exchange
Server\bin\exshell.psc1" -command Get-WMIObject MSCluster_ResourceGroup
-ComputerName MYEXCHANGE01 -Namespace root\mscluster -filter "name='Cluster
Group'" | Format-Table __Server

I get:

'Format-Table' is not recognized as an internal or external command,
operable program or batch file.

How can I get this to work?

Thanks.

Larry__Weiss

unread,
Nov 20, 2009, 5:18:27 PM11/20/09
to
Try (all on one line of course)

powershell.exe -psconsolefile "D:\Program Files\Microsoft\Exchange
Server\bin\exshell.psc1" -command "Get-WMIObject MSCluster_ResourceGroup
-ComputerName MYEXCHANGE01 -Namespace root\mscluster -filter name='Cluster
Group' | Format-Table __Server"

The main idea is to wrap double quotes around the PowerShell command, and not
using them inside the PowerShell command. The pipe was being interpreted at the
cmd.exe level and not the PowerShell level.

- Larry

0 new messages