我正在尝试使用 powershell 将应用程序安装到远程服务器上。这是我正在使用的脚本:
$cred = Get-Credential
$s = New-PSSession -ComputerName $ServerName -Credential $credInvoke-Command -Session $s -ScriptBlock {Start-Process -FilePath "c:\windows\system32\msiexec.exe" -ArgumentList "/i \\computer\e$\installer.msi /qn" -Wait}
Remove-PSSession -ComputerName $ServerName
如果我直接在远程计算机上运行以下命令,它会执行得很漂亮:
Start-Process -FilePath "c:\windows\system32\msiexec.exe" -ArgumentList "/i \\computer\e$\installer.msi /qn" -Wait
但是,当我将它作为调用命令的一部分远程运行时,PS session 打开,脚本运行,msiexec 在远程计算机上启动,然后 PS session 关闭,但应用程序永远不会安装,msiexec 也永远不会关闭。
如有任何帮助,我们将不胜感激。
谢谢,
扎克
最佳答案
您需要先将包复制到本地。 一旦开始远程处理,您就无法再使用 UNC。
目的地可以是服务器/计算机上的任何地方。
我使用温度,但它是任何你喜欢的。
我也喜欢使用 $env:windir\temp,以防万一。
Copy-item "\\servershare\File.msi" -conatiner -recurse `
\\$Computer\c$\windows\temp\
Invoke-Command -Computername $Computer -credential $cred -ScriptBlock {
Start-Process -FilePath `
"c:\windows\system32\msiexec.exe" `
-ArgumentList "/i `
\\computer\e$\installer.msi /qn" -Wait
}
希望对你有帮助。
关于windows - Powershell 调用命令的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25407353/