5

For some reason Start-Process msiexec won't work when run through invoke command on a remote machine. I looked it up and while some people recommend using psiexec i have seen a lot of people using the plain old invoke-command to start msi installers on remote machines.

This is the code i am currently using:

$session = New-PSSession -computername $computerName -ea stop

$command = {

    Param(
    [Parameter()]
    [string]$computerName,

    [Parameter()]
    [string]$domain,

    [Parameter()]
    [string]$user,

    [Parameter()]
    [string]$password,

    [Parameter()]
    [string]$installDir
    )

    $msiArgumentList = "/i C:\Installer.msi /l c:\log.txt /quiet /qr /norestart IAGREE=Yes DOMAIN=$domain ACCOUNT=$user PASSWORD=$password PASSWORDCONFIRM=$password INSTALLDIR=$installDir"

        Start-Process msiexec -ArgumentList $msiArgumentList -Wait

}

Invoke-Command -session $session -ScriptBlock $command -ArgumentList $computerName, $domain, $user, $password, $installDir

Remove-PSsession -session $session

I used the same method to install services remotely using intallutil and it worked. Scripting is enabled on target machine as well as remoting so by all accounts it should work. Both computers have the same credentials but i still tried adding credentials to both invoke-command and the pssession. I tested the code locally and the installation worked. Remotely it doesn't and no errors what so ever. i can see on the target machine in taskmanager that msiexec is started but nothing happens. I even tried disabling the firewall and still nothing. i tried the & operator to start msiexec and still nothing.

Not sure what else i could try.

user1752736
  • 105
  • 1
  • 3
  • 10

5 Answers5

1

You could try executing Start-Process with Passthru to see if an error is being returned:

(Start-Process -FilePath msiexec.exe -ArgumentList $msiArgumentList -Wait -Passthru).ExitCode

The other thing that may help is increasing your logging to /l*v


Update 1

Can you try the following, just to check remote commands for msi are working, it should result in 1619.

(Start-Process -FilePath msiexec.exe -ArgumentList "/i no.msi /quiet /qb!" -Wait -Passthru).ExitCode
David Martin
  • 11,764
  • 1
  • 61
  • 74
  • passthru did not help. nothing returned. tried -ea stop inside a try/catch to catch any non terminal errors but still nothing. and the log is never written sadly so increasing the logging doesn't help. – user1752736 Sep 10 '13 at 13:20
  • That's very odd, I install remotely using a very similar mechanism. I would have at least expected ExitCode to have a value either 0 or the usual 1619. – David Martin Sep 10 '13 at 13:35
  • I'm guessing that the parameters are incorrect and a dialog is being displayed, if you kill msiexec do you then get an exitcode? – David Martin Sep 10 '13 at 13:38
  • i checked for several hours for any possible problems and tried every workaround i found but nothing worked. – user1752736 Sep 10 '13 at 13:39
  • Does the start-process return immediately? – David Martin Sep 10 '13 at 13:40
  • yes. it takes maybe 1 sec till msiexec appear in taskmanager then the script continues/ends. when i kill the process still no exit code. – user1752736 Sep 10 '13 at 13:42
1

Maybe you try another way, if you don't come forward? Use Task scheduler, to start the command line e.g by creating and executing a task on the remote machine:

SchTasks /CREATE /XML mycommand.xml /TN "thiscommand"
SchTasks /RUN /TN "thiscommand"

This is for starting a task (like) on the local computer. With parameter /S you can create tasks on remote computers as in:

SchTasks /S thatPC /CREATE /XML mycommand.xml /TN "thiscommand"
SchTasks /S thatPC /RUN /TN "thiscommand"

For details of parameters and for syntax of the .xml file defining the task you can look into the help.

Philm
  • 3,448
  • 1
  • 29
  • 28
1

It seems the problem was a combination of how the msi installer was build and the restrictions windows server has towards interactive processes. I ended up using psexec to bypass this problem.

user1752736
  • 105
  • 1
  • 3
  • 10
0

The only solution that worked for me was to poll the process status. This can be run inside a scriptblock in a remote powershell session.

$res = Start-Process -FilePath $process -ArgumentList $arguments -Wait -PassThru

while ($res.HasExited -eq $false) { 
    Write-Host "Waiting for $process..."
    Start-Sleep -s 1
}

$exitCode = $res.ExitCode
user663470
  • 149
  • 7
0

Using the answers above I ended up with

$session = New-PSSession -ComputerName $serverName -Credential $mycred
invoke-command -Session $session -ScriptBlock { param ($argxs) write-host $argxs; start-process msiexec.exe -ArgumentList $argxs } -ArgumentList "/i `"$pathToMsi`" /qn /L*V `"E:\package.log`""

The write-host is just there to verify the augments are correctly escaped but proved invaluable in debugging.

rob
  • 8,134
  • 8
  • 58
  • 68