Exchange Server
(1)
WMIObject
(1)
MSCluster
(1)
ResourceGroup
(1)
Psconsolefile
(1)
MYEXCHANGE01
(1)

Powershell.exe troubles with spaces, quotes, and arguments

Asked By winnt
20-Nov-09 04:55 PM
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.

Try (all on one line of course)powershell.

Larry__Weiss replied to winnt
20-Nov-09 05:18 PM
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
Post Question To EggHeadCafe