0
我无法通过Invoke-Command
远程运行以下PowerShell脚本。PowerShell脚本与Invoke-Command不起作用
Invoke-Command
从服务器:
Invoke-Command -Session $session -Command {
Param($env:FileLocation, $file)
& "$env:FileLocation\$file"
} -ArgumentList ($env:FileLocation, $file) > ./windowsResult.txt
远程脚本:
$Process = Start-Process "$env:DATABASE_HOME\bin\psql.exe" -ArgumentList "-p "5433" -U "postgres" -d "TESTDB" -f $env:LOC_SCRIPT\DBTestScript.2.sql" -Wait -PassThru
if ($Process.ExitCode -eq 0) {
Write-Host "Success!!!!"
} else {
Write-Host "Error while executing DB Scripts"
}
当执行它的工作原理和数据库是越来越成功更新该远程脚本。
但是用Invoke-Command
调用它时没有。
有人可以帮助我吗?
请勿使用'env:'限定符作为参数:'{param($ FileLocation,$ file)&“$ FileLocation \ $ file”}' –
我们需要使用env,因为我们不知道放置在远程机器上的脚本的位置。我们正在使用环境变量来读取脚本的位置。 –
是的,在客户端(你仍然应该把'$ env:FileLocation'传递给'ArgumentList'),但是在远程scriptblock中你可以自己定义参数变量的名字。 –