脚本中的msiexec和pssession问题

时间:2019-06-12 12:00:09

标签: powershell powershell-remoting

我正在尝试编写一个Powershell脚本来安装.msi软件包。它需要用户输入(客户端的IP和用户名),然后创建一个新的PSSession并将文件从网络驱动器中拉出。

Enter-PSSession -ComputerName $destination -Credential <xxxxxx>
Invoke-Command -ScriptBlock {msiexec /i "\\CLOUD_IP\road-to\msi-location\msi_to_install.msi"}

这是脚本的主要问题。脚本完成后,安装程序将在我的PC而不是客户端的PC上提示,但仍保持会话状态。直到我手动或通过脚本退出会话。

当我在powershell提示符中手动输入这两行时,一切都按预期进行。

我试图在两行之间放置一个 Start-Sleep ,因为 Enter-PSSession 花费了一点时间,但是却什么也没做。

$ destination 是用户的IP输入,它也用作 -ComputerName ,因为 Get-PSSession 将IP显示为计算机名称

1 个答案:

答案 0 :(得分:0)

将其更改为:

Invoke-Command -ComputerName $destination -Credential <xxxxxx> -ScriptBlock {msiexec /i "\\CLOUD_IP\road-to\msi-location\msi_to_install.msi" /qn /quiet /norestart}
相关问题