如何在Windows上静默和自动部署和安装Github CLI ?



Github CLI repo在其最新版本中为Windows提供了MSI安装程序。我一直试图安装的文件是gh_2.10.1_windows_amd64.msi.

目标是能够在多台计算机上远程安装此程序,这意味着静默和自主安装是必要的。

我尝试执行各种Powershell命令,例如以下

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

Start-Process msiexec.exe -Wait -ArgumentList '/i "C:UsersmyUserDownloadsgh_2.10.1_windows_amd64.msi" /q /le "C:Install.log"'

以及我从各种论坛和Stackoverflow帖子中尝试的许多其他各种排列和选项。

当我尝试静默安装它时,命令执行并且似乎立即完成。

未安装Github CLI

。如果我运行如下命令:

msiexec /i C:UsersmyUserDownloadsgh_2.10.1_windows_amd64.msi

出现一个设置GUI,我需要点击它来安装。

如何通过Powershell安装远程部署和安装该软件?

我意识到它也可以安装choco,scoop,winget等。但是,不能保证在每个系统上都有到这些服务的网络连接。因此,我需要打包msi并以这种方式在本地安装,以便100%确定系统上的安装已经完成。

编辑

似乎以管理员身份运行Powershell可以安静地进行安装,而不需要任何输入。但这需要确认UAC提示。这对于远程更新是不可能的。我能做什么?

从其中一个答案运行以下代码后:

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

安装完成并生成日志。但是,发生了一个错误。下面是日志中产生错误的区域的代码片段:

Property(S): PrimaryVolumeSpaceAvailable = 0
Property(S): PrimaryVolumeSpaceRequired = 0
Property(S): PrimaryVolumeSpaceRemaining = 0
Property(S): INSTALLLEVEL = 1
Property(S): SOURCEDIR = C:UsersmyUserDownloads
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_MACHINESoftwareMicrosoftWindowsCurrentVersionInstallerRollbackScripts 3: 2 
MSI (s) (A4:EC) [12:45:54:513]: Note: 1: 1402 2: HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionInstallerRollbackScripts 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 ===

根据下面的一些评论,我已经尝试在不同的系统上运行上述命令,因为1603错误显然可能与某些文件夹有关。然而,在不同的系统上,它说我没有足够的特权。

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.
  • 如您所述,安静(无人值守,无ui)安装需要从提升的会话运行。

  • 在PowerShell通过Invoke-Command-ComputerName进行远程操作的上下文中,远程会话自动且总是与提升一起运行——假设目标用户是远程机器上BUILTINAdministrators组的成员。

因此,尝试如下操作(假设当前用户是目标计算机上的管理员):

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%TempGitHubCLI-Install.log'
if ($LASTEXITCODE -ne 0) { throw "Installation failed with exit code $LASTEXITCODE." }
}
要在本地机器上运行安装程序-从提升的会话-只需直接从上面的脚本块运行命令,即:
# Must run WITH ELEVATION.
# Check $LASTEXITCODE afterwards.
cmd /c 'MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%TempGitHubCLI-Install.log'

或者在ps5中(作为管理员):

install-package gh_2.10.1_windows_amd64.msi

不幸的是,-additionalarguments参数不起作用。