powershell 缺少终结符错误?

powershell is missing the terminator error?

我尝试从 cmd 运行 这个命令:

powershell -command "& {&'get-wmiobject Win32_Product | Format-Table Name, LocalPackage}"

...它在 windows 7 上工作,但在我的 windows 服务器 2008 R2 x64-bitIi 上出现此错误:

 The string starting:
At line:1 char:5
+ & {& <<<< 'get-wmiobject Win32_Product | Format-Table Name, LocalPackage}
is missing the terminator: '.
At line:1 char:68
+ & {&'get-wmiobject Win32_Product | Format-Table Name, LocalPackage} <<<<
    + CategoryInfo          : ParserError: (get-wmiobject W..., LocalPackage}:
   String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

如何解决这个错误?我需要它从 cmd 到 运行!!

两种变体在这里都有效:

powershell -command "get-wmiobject Win32_Product | Format-Table Name, LocalPackage"
powershell -command "&{get-wmiobject Win32_Product | Format-Table Name, LocalPackage}"