Invoke-command缺少表达式运算符' - '

时间:2017-06-06 19:09:08

标签: windows powershell

invoke-command -computer hq128804 -scriptblock {powershell.exe -nonprofile -executionpolicy Bypass c:\Install-WMF5.ps1} 

错误:

Missing expression after unary operator '-'.
    + CategoryInfo          : NotSpecified: (Missing express...y operator '-'.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName        : hq128804

At line:1 char:2
+ - <<<< nonprofile -executionpolicy Bypass c:\Install-WMF5.ps1
    + CategoryInfo          : ParserError: (-:String) [], ParentContainsErrorR
   ecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator
NotSpecified: (:) [], RemoteException

我正在尝试运行位于另一台远程PC的根文件系统上的脚本。我希望能够执行此操作并更新PowerShell for 2000计算机。我在每个系统上都有更新文件,我只需要一种方法来执行Microsoft从我的机器上提供的.ps1文件。

1 个答案:

答案 0 :(得分:0)

你应该这样做:

Invoke-command -ComputerName hq128804 -scriptblock{powershell.exe -noprofile -executionpolicy Bypass -Command "& { c:\Install-WMF5.ps1}" }

注意:确保将ps1正确放置在上述路径中