2

我已經使用此論壇上的代碼提供了以下代碼。使用Powershell遠程安裝.msi

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文件未安裝。也許這個問題被標記爲重複,但仍然建議在做這些之前做一些編輯。

+0

@Kayasax:我可以打開一個遠程會話。但不工作。關於psexec我沒有那麼多想法。你可以請提供和編輯相同的。 thnx – user2068804

+0

任何錯誤信息從遠程會話運行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 ' –

+0

msiexec沒有錯誤消息。也請告訴我上面的代碼應該放在哪裏?我不清楚這個。 Thnx – user2068804

回答

1

作爲解決方法(缺少細節無助於解決問題),您可以使用第三方工具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 
+1

請問您是否可以修改上述腳本並告訴我是否可以修改上述代碼以安裝.exe文件。其實我試圖用PowerShell遠程修補SQL。請給你的建議 – user2068804

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 
0

它的正常工作與psexec.exe,我已經安裝了它更多的超過100個用戶的桌面。在clients.txt文件上設置用戶的IP地址。以下是我的代碼:

cls 
$computername = Get-Content 'C:\Setup\clients.txt' 
$sourcefile = "C:\Setup\MySyncSvcSetup.msi" 
$serviceName = "MySyncWinSvc" 
$adminUserName = "username" 
$adminPassword = "[email protected]" 
#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" 
}