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

Time:05-19

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?

CodePudding user response:

  • 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.:

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

CodePudding user response:

Or (as administrator):

install-package gh_2.10.1_windows_amd64.msi
  • Related