【问题标题】:Install .msi remotely using Powershell使用 Powershell 远程安装 .msi
【发布时间】:2015-07-06 20:27:05
【问题描述】:

我已使用此论坛上的代码让他遵循代码。

cls
$computername = Get-Content 'C:\Users\C201578-db\Documents\server.txt'
$sourcefile = "\\iceopsnas\LNT_SoftwareRep.grp\CORE\COTS\EMC\Avamar\Avamar_7.0\CR06794393\AvamarClient-windows-x86_64-7.0.102-47.msi"
#This section will install the software 
foreach ($computer in $computername) 
{
    $destinationFolder = "\\$computer\C$\Avamar"
    #This section will copy the $sourcefile to the $destinationfolder. If the Folder does not exist it will create it.
    if (!(Test-Path -path $destinationFolder))
    {
        New-Item $destinationFolder -Type Directory
    }
    Copy-Item -Path $sourcefile -Destination $destinationFolder
    Write-Host "Copied Successfully"
    Invoke-Command -ComputerName $computer -ScriptBlock { & cmd /c "msiexec.exe /i C:\Avamar\AvamarClient-windows-x86_64-7.0.102-47.msi" /qb ADVANCED_OPTIONS=1 CHANNEL=100}
    Write-Host "Installed Successfully"
}

我尝试了所有的排列和组合,但没有运气。尝试了发布此问题时得到的所有建议,但没有。复制过程成功,但未安装 .msi 文件。也许这个问题被标记为重复,但在这样做之前仍然建议进行一些编辑。

【问题讨论】:

  • @Kayasax:我可以打开一个远程会话。但不工作。关于 psexec 我没有那么多想法。您能否提供和编辑相同的内容。谢谢
  • 从远程会话运行 msiexec 的任何错误消息?对于 psexec 尝试类似psexec.exe \\$computer -s -u Adminuser -p AdminPassword msiexec /i C:\Avamar\AvamarClient-windows-x86_64-7.0.102-47.msi /qb ADVANCED_OPTIONS=1 CHANNEL=100
  • 没有来自 msiexec 的错误消息。另外请告诉我上面的代码应该放在哪里?我不清楚这一点。谢谢
  • 上面的代码是为了替换这一行Invoke-Command -ComputerName $computer -ScriptBlock { & cmd /c "msiexec.exe /i C:\Avamar\AvamarClient-windows-x86_64-7.0.102-47.msi" /qb ADVANCED_OPTIONS=1 CHANNEL=100}
  • @Kayasax:谢谢建议。我不知道如何在 powershell 中启用此功能。当我触发上述命令时,它说“psexec.exe”一词未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。

标签: powershell windows-installer windows-server-2008-r2 powershell-remoting


【解决方案1】:

psexec.exe 运行良好,我已将它安装在 100 多个用户的桌面上。在clients.txt 文件中设置用户的IP 地址。以下是我的代码:

cls
$computername = Get-Content 'C:\Setup\clients.txt'
$sourcefile = "C:\Setup\MySyncSvcSetup.msi"
$serviceName = "MySyncWinSvc"
$adminUserName = "username"
$adminPassword = "password@123"
#This section will install the software 
foreach ($computer in $computername) 
{
    #First uninstall the existing service, if any
    C:\PSTools\psexec.exe \\$computer -s -u $adminUserName -p $adminPassword msiexec.exe /x C:\SetupFiles\MySyncSvcSetup.msi /qb
    Write-Host "Uninstalling Service"
    $destinationFolder = "\\$computer\C$\SetupFiles"
    #This section will copy the $sourcefile to the $destinationfolder. If the Folder does not exist it will create it.
    if (!(Test-Path -path $destinationFolder))
    {
        New-Item $destinationFolder -Type Directory
    }
    Copy-Item -Path $sourcefile -Destination $destinationFolder
    Write-Host "Files Copied Successfully"
    C:\PSTools\psexec.exe \\$computer -s -u $adminUserName -p $adminPassword msiexec.exe /i C:\SetupFiles\MySyncSvcSetup.msi /qb /l* out.txt
    Write-Host "Installed Successfully"
    C:\PSTools\psexec.exe \\$computer -s -u $adminUserName -p $adminPassword sc.exe start $serviceName
    Write-Host "Starting the Service"
}

【讨论】:

    【解决方案2】:

    尝试将您的命令定义为脚本块:

        $command =  "msiexec.exe /i C:\Avamar\AvamarClient-windows-x86_64-7.0.102-47.msi" 
        $scriptblock = [Scriptblock]::Create($command)
        Invoke-Command -ComputerName $computer -ScriptBlock $scriptblock
    

    【讨论】:

      【解决方案3】:

      作为一种解决方法(缺少详细信息无助于诊断问题),您可以使用第三方工具 psexec.exe 在远程主机上运行安装程序。

      尝试用

      替换您的调用命令
      psexec.exe \\$computer -s -u Adminuser -p AdminPassword msiexec /i C:\Avamar\AvamarClient-windows-x86_64-7.0.102-47.msi /qb ADVANCED_OPTIONS=1 CHANNEL=100
      

      【讨论】:

      • 能否请您修改上述脚本并告诉我是否可以修改上述代码以安装.exe 文件。实际上,我正在尝试使用 powershell 远程修补 SQL。请给你的建议
      猜你喜欢
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      • 2013-07-23
      • 1970-01-01
      相关资源
      最近更新 更多