windows - Powershell 调用命令的问题

标签 windows powershell powershell-3.0

我正在尝试使用 powershell 将应用程序安装到远程服务器上。这是我正在使用的脚本:

$cred = Get-Credential
$s = New-PSSession -ComputerName $ServerName -Credential $cred

Invoke-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/

相关文章:

c - 为什么这个 C 代码在没有 cygwin 的情况下可以在 linux 上运行,但不能在 Windows 上运行

c++ - 如何将 Windows 窗体应用程序 (C++) 设置为具有 Aero/Glass 背景?

powershell - 发送请求时在 PowerShell 中使用括号

json - PowerShell : retrieve JSON object by field value

arrays - 替换 powershell 数组中的字符串

ruby-on-rails - Rails 3.0 开发用于部署在另一个操作系统上的 SQL 服务器上

mysql - 为什么在删除 MySQL 表的某些行后我的可用磁盘空间减少了?

powershell - 在 PowerShell 中导出为 CSV 时如何指定列顺序?

powershell - 使用Powershell脚本获取字符串中具有特定日期的文件

azure - 为什么在调用其中包含 azure commandlet 的脚本时未出现 write-host 语句?