How to silently and automatically deploy and install Github CLI on Windows?

Issue

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.

Solution

  • 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'

Answered By – mklement0

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published