1

The Github CLI repo has an MSI installer for Windows in their latest release. The file I have been trying to install is gh_2.10.1_windows_amd64.msi.

The objective is to be able to install this program remotely across many computers, meaning a silent and autonomous install is necessary.

I have tried to perform a variety of Powershell commands, such as the following

MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log

Or

Start-Process msiexec.exe -Wait -ArgumentList '/i "C:\Users\myUser\Downloads\gh_2.10.1_windows_amd64.msi" /q /le "C:\Install.log"'

And many other various permutations and options that I've been trying from various forum and Stackoverflow posts.

When I try to install it silently, the command executes and seems to immediately finish. However, Github CLI is not installed.

If I run something like:

msiexec /i C:\Users\myUser\Downloads\gh_2.10.1_windows_amd64.msi

A setup GUI appears that I need to click through for it to install.

How can I remotely deploy and install this software by installing through Powershell?

I realize it can also be installed with choco, scoop, winget etc. However, a network connection to these services is not guaranteed at each system. So I need to package the msi and install locally that way in order to be 100% certain the install is completed on the systems.

Edit

It appears running Powershell as administrator allows the install to occur quietly without any input needed. But this requires confirming the UAC prompt. This is not possible for a remote update. What can I do?

After running the following code from one of the answers:

# Check $LASTEXITCODE afterwards.
cmd /c 'MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log'

The install occurred and logs were produced. However, an error occurred. Here is a snippet around the area where the error was produced in the logs:

Property(S): PrimaryVolumeSpaceAvailable = 0
Property(S): PrimaryVolumeSpaceRequired = 0
Property(S): PrimaryVolumeSpaceRemaining = 0
Property(S): INSTALLLEVEL = 1
Property(S): SOURCEDIR = C:\Users\myUser\Downloads\
Property(S): SourcedirProduct = {6E9B412F-42F0-4819-BDFF-3BFE1A28F531}
Property(S): ProductToBeRegistered = 1
MSI (s) (A4:DC) [12:45:54:500]: Note: 1: 1708 
MSI (s) (A4:DC) [12:45:54:500]: Note: 1: 2205 2:  3: Error 
MSI (s) (A4:DC) [12:45:54:500]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1708 
MSI (s) (A4:DC) [12:45:54:500]: Note: 1: 2205 2:  3: Error 
MSI (s) (A4:DC) [12:45:54:500]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1709 
MSI (s) (A4:DC) [12:45:54:500]: Product: GitHub CLI -- Installation failed.

MSI (s) (A4:DC) [12:45:54:500]: Windows Installer installed the product. Product Name: GitHub CLI. Product Version: 2.10.1. Product Language: 1033. Manufacturer: GitHub, Inc.. Installation success or error status: 1603.

MSI (s) (A4:DC) [12:45:54:506]: Deferring clean up of packages/files, if any exist
MSI (s) (A4:DC) [12:45:54:506]: MainEngineThread is returning 1603
MSI (s) (A4:EC) [12:45:54:509]: RESTART MANAGER: Session closed.
MSI (s) (A4:EC) [12:45:54:509]: No System Restore sequence number for this installation.
=== Logging stopped: 2022-05-18  12:45:54 ===
MSI (s) (A4:EC) [12:45:54:512]: User policy value 'DisableRollback' is 0
MSI (s) (A4:EC) [12:45:54:512]: Machine policy value 'DisableRollback' is 0
MSI (s) (A4:EC) [12:45:54:512]: Incrementing counter to disable shutdown. Counter after increment: 0
MSI (s) (A4:EC) [12:45:54:512]: Note: 1: 1402 2: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Rollback\Scripts 3: 2 
MSI (s) (A4:EC) [12:45:54:513]: Note: 1: 1402 2: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Rollback\Scripts 3: 2 
MSI (s) (A4:EC) [12:45:54:513]: Decrementing counter to disable shutdown. If counter >= 0, shutdown will be denied.  Counter after decrement: -1
MSI (c) (88:D8) [12:45:54:515]: Decrementing counter to disable shutdown. If counter >= 0, shutdown will be denied.  Counter after decrement: -1
MSI (c) (88:D8) [12:45:54:517]: MainEngineThread is returning 1603
=== Verbose logging stopped: 2022-05-18  12:45:54 ===

As per some comments below, I have tried to run the above command on a different system, since the 1603 error is probably related to some folder apparently. However, on the different system, it is saying that I have insufficient privileges.

MSI (s) (20:38) [16:48:34:696]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1709 
MSI (s) (20:38) [16:48:34:696]: Product: GitHub CLI -- Error 1925. You do not have sufficient privileges to complete this installation for all users of the machine.  Log on as administrator and then retry this installation.

Error 1925. You do not have sufficient privileges to complete this installation for all users of the machine.  Log on as administrator and then retry this installation.
geekygeek
  • 611
  • 4
  • 15
  • I believe you are missing the `/quiet` option which is needed to run with no user interaction. – Daniel May 18 '22 at 17:07
  • Thanks. I just tried that and same result. – geekygeek May 18 '22 at 17:11
  • 1
    @Daniel, `/qn` and `/q` (as used in the question) are the same as `/quiet` – mklement0 May 18 '22 at 17:23
  • Ah right, thanks @mklement0. @geekygeek, try this `Start-Process -FilePath msiexec -ArgumentList "/i 'C:\Users\myUser\Downloads\gh_2.10.1_windows_amd64.msi' /qb+ /L*v ${env:windir}\Temp\Test.log"` If that works you can change the /qb+ to /qn or whatever you want. Specify the fullpath to the msi installer and the log. Be careful with spaces in which case you will need to surround with quotes. – Daniel May 18 '22 at 18:04

2 Answers2

2
  • As you state, quiet (unattended, no-UI) installation requires running from an elevated session.

  • In the context of PowerShell remoting via Invoke-Command -ComputerName, a remote session automatically and invariably runs with elevation - assuming that the target user is a member of the BUILTIN\Administrators group on the remote machine.

Therefore, try something like the following (assumes that the current user is an administrator on the target machines):

Invoke-Command -Computer $computers -ScriptBlock {
  # Use of cmd /c ensures *synchronous* execution
  # (and also interprets %WINDIR% as intended).
  cmd /c 'MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log'
  if ($LASTEXITCODE -ne 0) { throw "Installation failed with exit code $LASTEXITCODE." }
}

To run the installer on the local machine - from an elevated session - simply run the command from the script block above directly, i.e.:

# Must run WITH ELEVATION.
# Check $LASTEXITCODE afterwards.
cmd /c 'MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log'
mklement0
  • 382,024
  • 64
  • 607
  • 775
  • @geekygeek, please see my update. – mklement0 May 18 '22 at 18:41
  • Thank you very much. The installation did run this time! It did also produce some errors in the logs and updated my post to show those errors. In either case, it is a step forward. I appreciate your answer, thanks. – geekygeek May 18 '22 at 18:52
  • Glad to hear we made a step forward, @geekygeek. As for error `1603`, see https://learn.microsoft.com/en-US/troubleshoot/windows-server/application-management/msi-installation-error-1603. A common reason for this error is not actually running _with elevation_, a less common one is a "ghost" folder that cannot be removed, which is fixed by a reboot. – mklement0 May 18 '22 at 20:16
  • Thank you. I tried running it on a different system since you mentioned the previous error could be something with the OS, and now I am receiving `Error 1925` which is saying I don't have enough privileges. I have updated my post with some logs – geekygeek May 18 '22 at 22:51
  • @geekygeek, so, are you running from an elevated session? – mklement0 May 18 '22 at 22:53
  • I see. I just opened up `powershell` and ran the command. So I guess for remote deployments, I would need to manually run this command with elevation, by right clicking and running as administrator? – geekygeek May 18 '22 at 22:54
  • @geekygeek, when running _locally_, you must enter an _elevated session_ (run as admin) before running your command, as (hopefully) clearly implied in the answer. When running _remotely_, you needn't worry about elevation, as long as the user account in which the remote command executes is a member of the Administrators group on the target machine(s), as such sessions are _implicitly_ elevated. – mklement0 May 18 '22 at 22:57
0

Or in PS 5 (as administrator):

install-package gh_2.10.1_windows_amd64.msi

Unfortunately, the -additionalarguments parameter doesn't work.

js2010
  • 23,033
  • 6
  • 64
  • 66
  • That's a convenient option, assuming that (a) you're running on _Windows PowerShell_ (not supported in PowerShell (Core) 7+) and (b) you don't need to customize the installation with options such as `/L*v "$env:WINDIR\Temp\GitHubCLI-Install.log"`. While the `msi` package provider does have a dynamic `-ArgumentList` property, it seems that any arguments you pass to it are _ignored_. – mklement0 May 18 '22 at 22:59
  • 1
    @mklement0 You mean -additionalarguments, but yes looks like it's been a bug since 2018, and ps7 doesn't support msi -- "MSI Provider Does Not Implement AdditionalArguments · Issue #334 · OneGet_oneget · GitHub" https://github.com/OneGet/oneget/issues/334 – js2010 May 19 '22 at 19:27
  • Yes, `-AdditionalArguments` is what I meant, thanks; thanks for the GitHub link. – mklement0 May 19 '22 at 20:00