小编use*_*678的帖子

Powershell:在scriptblock中出现问题

我运行以下命令时遇到问题

$x =  "c:\Scripts\Log3.ps1"
$remoteMachineName = "172.16.61.51"
Invoke-Command -ComputerName $remoteMachineName  -ScriptBlock {& $x}

The expression after '&' in a pipeline element produced an invalid object. It must result in a command name, script
block or CommandInfo object.
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : BadExpression
    + PSComputerName        : 172.16.61.51
Run Code Online (Sandbox Code Playgroud)

如果我不使用$x变量,则不会出现问题

Invoke-Command -ComputerName $remoteMachineName  -ScriptBlock {& 'c:\scripts\log3.ps1'}

    Directory: C:\scripts


Mode                LastWriteTime     Length Name                                  PSComputerName
----                -------------     ------ ----                                  --------------
-a---         7/25/2013   9:45 PM          0 new_file2.txt                         172.16.61.51
Run Code Online (Sandbox Code Playgroud)

powershell powershell-remoting

6
推荐指数
1
解决办法
6950
查看次数

标签 统计

powershell ×1

powershell-remoting ×1