powershell - How can I use Psconsole.psc1 -Command Get-{anything} -


i working powershell scripts executed way:

ps c:\long\path\to\psconsole.psc1  -command  {get-whatever...}  

they generate error:

you must provide value expression on right hand side of value '-' operator.*

here's example:

ps  c:\>  "c:\program files\common files\microsoft shared\web server extensions\14\config\powershell\registration\psconsole.psc1" -command "get-service" 

same error message:

`you must provide value expression on right hand side of value '-' operator.` ... @ line 1...  - <<< command "get-service"   + categoryinfo:         pasererror: (:) [], parentcontainserrorrecordexception   + fullyqualifiederror:   expectedvalueexpression 

can tell me way -command working?

by enclosing path in quotes, you're telling powershell string , - before "-command" interpreted operator not parameter.

to around this, prefix statement "call" operator "&":

 & "c:\program files\common files\microsoft shared\web server extensions\14\config\powershell\registration\psconsole.psc1" -command "get-service" 

edit: if use tab key autocompletion of path, console automatically put & call operator there when sees space in full path.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -