tags:

views:

523

answers:

4

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 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.

A: 

put quotes around "-WindowStyle Hidden" ?

ghostdog74
I get the same error
magol
A: 

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?

stej
magol
What is the whole command line that you run after the quoting I suggest? And does it work if you remove the `-WindowStyle Hidden`?
stej
If I remove -WindowStyle Hidden the powershell shell start, but the script dont run
magol
+1  A: 

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.

Keith Hill
Yes, I want to hide the window. It was developed on 2.0 and I try to run it on the same machine.
magol
On the machine it fails on, what info does $PSVersionTable return?
Keith Hill
A: 

Do anyone have the solution? I have to solve it today

magol