开发者

Get "Missing expression after unary operator '-'" when I try to run a Powershell script

When I try to run following command

C:\Documents and Settings\BURE\My Documents\ibos\script>powershell.exe  -NoProfile -WindowStyle Hidden & 'C:\Documents and Settings\BURE\My Documents\ibos\script\files_from_nomad.ps1' 1

I get following error

Missing expression after unary operator '-'.
At line:1 char:2
+ - <<<< WindowStyle Hidden
The filename, directory name, or volume label syntax is incorrect.

It works before, but not now? Why?

What I try to do is to schadular开发者_StackOverflow社区 a script:

schtasks /CREATE /RU BURE /SC MINUTE /TN files_to_nomad   /TR "powershell.exe  -NoProfile -WindowStyle Hidden & 'C:\Documents and Settings\BURE\My Documents\ibos\script\files_to_nomad.ps1' 1"

I have exact the same schedular on another computer.


I get the same error when I try to execute your command (but with double quotes around & to 1) on PowerShell 1.0. 1.0 doesn't support the WindowStyle parameter. Is it possible you are developing this on 2.0 but then testing it out on a PowerShell 1.0 system? Also, if you are running this from PowerShell 2.0 this will make the current window hidden. Is that your intent? You could fire the script off in another, hidden PowerShell window using Start-Process -WindowStyle Hidden.


put quotes around "-WindowStyle Hidden" ?


Maybe the command should be quoted:

powershell.exe -NoProfile -WindowStyle Hidden "& 'C:\Docum...\script\files_from_nomad.ps1' 1"

Besides that - have you tried to remove -WindowStyle Hidden? What does it do then?


arguments : -file "C:\Program Files\path\to\pcp\script.php"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜