0

I am trying to run an msiinstaller file on a remote system using the invoke-command. I have tried a couple of different methods but both have been unsuccessful to this point. They don't error out but they don't seem to run the install on the remote system either. At least as far as I can tell. Nothing in the event log, still on the old version of software I am trying to update.

I will post both methods here to see if either one of them is close and someone can get me over the top. thanks in advance. [I tend to get confused with how to properly use the invoke command so please cut me some slack if I am totally off base on these attempts.]

common for both: using get-credential to load up var $cred var targetHost is the remote system

first method:

$MsiInstallPath = "c:\Temp\MSI\file.msi"
$MsiArguments = " /i `"$MsiInstallPath`" /q SITE_TOKEN='adsfads' "
invoke-command -ComputerName $targetHost -Scriptblock { param($msi_args) Start-Process msciexec.exe -ArgumentList $msi_args } -ArgumentList $MsiArguments

second method:

$scriptblock = { Start-Process msiexec.exe -ArgumentList "/i $MsiInstallPath", "/q", "SITE_TOKEN='abcd'" }
invoke-command -ComputerName $targetHost -Credential $cred -ScriptBlock $scriptblock

Any insight or assistance would be most appreciated. Thanks D

dontron
  • 1
  • 1
  • Add `/l*v c:\Temp\MSI\install.log` to the `msiexec` arguments. It will contain details about any errors. – zett42 Mar 11 '22 at 19:14
  • Second method is incorrect. Use `$using:MsiInstallPath` to refer to the variable which is declared outside of the script block. See [example](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-7.2#example-9--include-local-variables-in-a-command-run-on-a-remote-computer) – zett42 Mar 11 '22 at 19:16
  • Regarding elevated permissions see [this answer](https://stackoverflow.com/a/65024701/7571258). – zett42 Mar 11 '22 at 19:20
  • There is no need to use `Start-Processs` here. Try this: `$MsiArguments = '/i', $MsiInstallPath, '/q', '/l*v C:\Temp\MSI\install.log', "SITE_TOKEN='adsfads'"; invoke-command -ComputerName $targetHost -Credential $cred -Scriptblock { msiexec $using:MsiArguments; "msiexec returned $LastExitCode" }` -- this will output [exit code of msiexec](https://learn.microsoft.com/en-us/windows/win32/msi/error-codes) in case log file isn't written. – zett42 Mar 11 '22 at 19:28
  • I used your code snippet and made my actual variable changes, but the LastExitCode came back blank when it completed. Nothing was in the \Temp\MSI\ for logs. any other suggestions? – dontron Mar 11 '22 at 21:01
  • Actually you need `Start-Process` to get exit code from msiexec because it is a GUI process that normally runs detached. `$MsiArguments = '/i', $MsiInstallPath, '/q', '/l*v C:\Temp\MSI\install.log', "SITE_TOKEN='adsfads'"; invoke-command -ComputerName $targetHost -Credential $cred -Scriptblock { $exitCode = (Start-Process msiexec.exe -ArgumentList $using:MsiArguments -Wait -PassThru).ExitCode; "msiexec returned $exitCode" }` – zett42 Mar 11 '22 at 21:52
  • 1
    Thanks very much. I'm almost there but I'm getting a 1603 error code. But I wouldn't have gotten that far without your help. Much appreciated. – dontron Mar 14 '22 at 14:46
  • When you get an error 1603, search for "value 3" (localized in the actual language of the MSI) in the MSI log file. The actual cause of error is usually located a few lines before that. – zett42 Mar 14 '22 at 15:12

0 Answers0