简体   繁体   English

使用Powershell远程安装.msi

[英]Install .msi remotely using Powershell

I have made he following code using the code present on this forum. 我使用此论坛上的代码使他遵循代码。

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"
}

I tried all permutations and combinations but no luck. 我尝试了所有的排列和组合,但没有运气。 Tried all the suggestions that I got while posting this question but nothing. 尝试了在发布这个问题时得到的所有建议,但没有。 The copy procedure is successful but the .msi file is not getting installed. 复制过程成功但未安装.msi文件。 Maybe this question gets marked duplicate but still suggest some edits before doing that. 也许这个问题会被标记为重复,但在此之前仍然建议进行一些编辑。

try defining your command as a script block instead: 尝试将命令定义为脚本块:

    $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

As a workaround (the lack of details doesnt help to daignose the problem), you could use the third party tool psexec.exe to run the installer on the remote host. 作为一种解决方法(缺少详细信息无助于解决问题),您可以使用第三方工具psexec.exe在远程主机上运行安装程序。

Try to replace your invoke-command with 尝试用。替换你的invoke命令

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

It's working fine with psexec.exe, I have installed it on more than 100 user's desktop. 它与psexec.exe工作正常,我已经在100多个用户的桌面上安装了它。 Setup your user's ip addresses on clients.txt file. 在clients.txt文件上设置用户的ip地址。 Below is my code : 以下是我的代码:

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"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM