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