Powershell 使用Invoke命令在虚拟机上运行脚本

Powershell 使用Invoke命令在虚拟机上运行脚本,powershell,powershell-2.0,powershell-3.0,powershell-4.0,Powershell,Powershell 2.0,Powershell 3.0,Powershell 4.0,我写了这段代码: $vmName = $args[0] $sign_check_tool = $args[1] $arguments = $args[2] $remote_session = New-PSSession -VMName $vmName -Credential $cred try { Invoke-Command -Session $remote_session -Block { $signcheck_output = ./$using:sign_check_tool

我写了这段代码:

$vmName = $args[0]
$sign_check_tool = $args[1]
$arguments = $args[2]

$remote_session = New-PSSession -VMName $vmName -Credential $cred

try {
Invoke-Command -Session $remote_session -Block {

   $signcheck_output = ./$using:sign_check_tool /accepteula -c $using:arguments

   Write-Output "${signcheck_output }"

}
} catch [Exception] {
    Remove-PSSession $remote_session
    exit 1
}

Exit-PSSession
我想为几个作为参数接收的签名检查工具以及不同的安装程序运行此脚本。但我得到了这个错误:

The term './$using:sign_check_tool' is not recognized as the name of a cmdlet, function,  file, or operable 

我想把几种类型的工具作为参数传递给同一个安装程序,但是我得到了前面的错误。如果您能帮助我,我将不胜感激。

我想您需要将
$using:sign\u check\u tool
传递到
-ArgumentList
,以便提取,例如:

Invoke-Command -Session $remote_session -Block -ArgumentList $using:sign_check_tool, $using:arguments {
   param($tool, $args)

   $signcheck_output = ./$tool /accepteula -c $args

   Write-Output "${signcheck_output }"

}

如果您想调用这些工具,远程主机应该安装这些工具。如果没有,您可以向映射网络驱动器添加代码并上载完成任务所需的可执行文件。在调用此代码之前,我会复制该计算机上需要的所有内容,包括简单的.exe文件工具和正在测试的文件。当我尝试从python调用此代码并尝试打印输出时,我得到“None”还有一个必须添加的参数
$using:arguments
,更新了我的帖子,请重试。错误似乎持续存在,我对该脚本进行了子处理,当我想要打印输出时,我没有得到任何结果。我会尝试其他解决方案,如果我成功了,我会把解决方案放在这里。