当我尝试运行以下命令时
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
我收到以下错误
Missing expression after unary operator '-'.
At line:1 char:2
+ - <<<< WindowStyle Hidden
The filename, directory name, or volume label syntax is incorrect.
以前可以用,现在不行了? 为什么?
我尝试做的是安排一个脚本:
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"
我在另一台计算机上有完全相同的时间表。
最佳答案
当我尝试在 PowerShell 1.0 上执行您的命令(但在 &
到 1
之间使用双引号)时,我遇到了相同的错误。 1.0 不支持 WindowStyle 参数。您是否有可能在 2.0 上开发它,然后在 PowerShell 1.0 系统上测试它?另外,如果您从 PowerShell 2.0 运行此命令,这将使当前窗口隐藏。这是你的意图吗?您可以使用 Start-Process -WindowStyle Hidden 在另一个隐藏的 PowerShell 窗口中启动脚本。
关于powershell - 当我尝试运行 Powershell 脚本时获取 "Missing expression after unary operator ' -'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2200387/