powershell - 当我尝试运行 Powershell 脚本时获取 "Missing expression after unary operator ' -'"

标签 powershell

当我尝试运行以下命令时

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/

相关文章:

powershell - 如何使用powershell运行批处理文件

powershell - 使用 PowerShell 转换 Unix 时间

powershell - 如何使用 Export-Csv 将 powershell 的哈希表导出为 CSV 文件?

powershell - Select 方法返回类似 @{Name= 的字符串

powershell - 使用另一个参数值验证参数值

powershell - 如何初始化自定义对象数组

.net - 使用 PowerShell 时出现内存泄漏

powershell - 使用 Powershell 从文件中删除最后一行

windows - 用于验证 IIS 设置的 Powershell 脚本

.net - 默认 XML 命名空间是否需要前缀?