3

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. Maybe this question gets marked duplicate but still suggest some edits before doing that.

7
  • @Kayasax: I'm able to open a remote session. But not working. Regarding psexec I don't have that much idea. can you please provide and edit for the same. thnx Commented Apr 28, 2015 at 6:47
  • any error msg running msiexec from the remote session ? for psexec try something like 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 Commented Apr 28, 2015 at 6:54
  • No error msg from msiexec. Also please tell me where should the above code be placed?? I'm not clear abt this. Thnx Commented Apr 28, 2015 at 7:26
  • the code above is meant to replace this line 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} Commented Apr 28, 2015 at 7:27
  • @Kayasax: Thnx for suggestion. I don't know how to enable this functionality in powershell. When i fired the above command, it said The term 'psexec.exe' is not recognized as the name of a cmdlet, function, scri pt file, or operable program. Commented Apr 28, 2015 at 10:43

3 Answers 3

1

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.

Try to replace your invoke-command with

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
  • 1
    Could you please modify the above script and tell me if it is possible to modify the above code for installing an .exe file. Actually i'm trying to patch SQL remotely using powershell. Kindly give ur suggestion Commented May 2, 2015 at 15:02
1

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
1
  • This is a more complicated version of Invoke-Command -ComputerName $computer -ScriptBlock { msiexec.exe /i C:\Avamar\AvamarClient-windows-x86_64-7.0.102-47.msi }, is missing arguments, and will run asynchronously (the use of cmd /c in the code in the question implicitly makes the call synchronous)
    – mklement0
    Commented Sep 7, 2023 at 17:11
0

It's working fine with psexec.exe, I have installed it on more than 100 user's desktop. Setup your user's ip addresses on clients.txt file. 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"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.