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.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
user2068804
  • 55
  • 1
  • 3
  • 12
  • @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 – user2068804 Apr 28 '15 at 06: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` – Loïc MICHEL Apr 28 '15 at 06:54
  • No error msg from msiexec. Also please tell me where should the above code be placed?? I'm not clear abt this. Thnx – user2068804 Apr 28 '15 at 07: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}` – Loïc MICHEL Apr 28 '15 at 07: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. – user2068804 Apr 28 '15 at 10:43
  • @Kayasax: I placed the psexec in the executable path. but again getting the same error. if i'm executing the statement given by you locally, it's executing fine. Why such discrepancy – user2068804 Apr 28 '15 at 11:04
  • @Kayasax: Thank you very much for your prompt response. I figured it out. The changes suggested by you is working fine and the installation is happening properly. Thanks again for being so much patient with me. – user2068804 Apr 28 '15 at 11:48

3 Answers3

2

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
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
Mathieu Diepman
  • 151
  • 1
  • 11
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
Loïc MICHEL
  • 24,935
  • 9
  • 74
  • 103
  • 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 – user2068804 May 02 '15 at 15:02
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"
}
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
VikasChauhan
  • 61
  • 1
  • 3