如何在 Windows 上静默自动部署和安装 Github CLI?
How to silently and automatically deploy and install Github CLI on Windows?
Github CLI repo has an MSI installer for Windows
in their latest release。我一直试图安装的文件是 gh_2.10.1_windows_amd64.msi
.
objective 是为了能够在多台计算机上远程安装此程序,这意味着静默和自主安装是必要的。
我尝试执行了多种Powershell
命令,例如下面的
MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log
或
Start-Process msiexec.exe -Wait -ArgumentList '/i "C:\Users\myUser\Downloads\gh_2.10.1_windows_amd64.msi" /q /le "C:\Install.log"'
以及我一直在各种论坛和 Whosebug 帖子中尝试的许多其他各种排列和选项。
当我尝试静默安装时,命令执行并似乎立即完成。但是,Github CLI
没有安装。
如果我 运行 是这样的:
msiexec /i C:\Users\myUser\Downloads\gh_2.10.1_windows_amd64.msi
出现一个安装 GUI,我需要点击它才能安装。
如何通过Powershell
安装远程部署安装此软件?
我知道它也可以与 choco
、scoop
、winget
等一起安装。但是,不能保证每个系统都能连接到这些服务。所以我需要打包 msi 并以这种方式在本地安装,以便 100% 确定安装已在系统上完成。
编辑
出现 运行ning Powershell
是因为管理员允许安装安静地进行,无需任何输入。但这需要确认UAC提示。这对于远程更新是不可能的。我能做什么?
运行从其中一个答案中获取以下代码后:
# Check $LASTEXITCODE afterwards.
cmd /c 'MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log'
已安装并生成了日志。但是,发生错误。以下是日志中产生错误的区域周围的片段:
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 ===
根据下面的一些评论,我已尝试 运行 在不同的系统上执行上述命令,因为 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.
如您所述,安静(无人值守,no-UI)安装需要从 提升的 会话中进行 运行ning。
在 PowerShell remoting via Invoke-Command
-ComputerName
的上下文中,远程会话 自动且总是 运行 具有提升- 假设目标用户是远程计算机上 BUILTIN\Administrators
组的成员。
因此,尝试如下操作(假设当前用户是目标机器的管理员):
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." }
}
到 运行 local 机器上的安装程序 - 来自 elevated 会话 - 只需 运行直接来自上面脚本块的命令,即:
# 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'
或在 PS 5(作为管理员):
install-package gh_2.10.1_windows_amd64.msi
遗憾的是,-additionalarguments 参数不起作用。
Github CLI repo has an MSI installer for Windows
in their latest release。我一直试图安装的文件是 gh_2.10.1_windows_amd64.msi
.
objective 是为了能够在多台计算机上远程安装此程序,这意味着静默和自主安装是必要的。
我尝试执行了多种Powershell
命令,例如下面的
MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log
或
Start-Process msiexec.exe -Wait -ArgumentList '/i "C:\Users\myUser\Downloads\gh_2.10.1_windows_amd64.msi" /q /le "C:\Install.log"'
以及我一直在各种论坛和 Whosebug 帖子中尝试的许多其他各种排列和选项。
当我尝试静默安装时,命令执行并似乎立即完成。但是,Github CLI
没有安装。
如果我 运行 是这样的:
msiexec /i C:\Users\myUser\Downloads\gh_2.10.1_windows_amd64.msi
出现一个安装 GUI,我需要点击它才能安装。
如何通过Powershell
安装远程部署安装此软件?
我知道它也可以与 choco
、scoop
、winget
等一起安装。但是,不能保证每个系统都能连接到这些服务。所以我需要打包 msi 并以这种方式在本地安装,以便 100% 确定安装已在系统上完成。
编辑
出现 运行ning Powershell
是因为管理员允许安装安静地进行,无需任何输入。但这需要确认UAC提示。这对于远程更新是不可能的。我能做什么?
运行从其中一个答案中获取以下代码后:
# Check $LASTEXITCODE afterwards.
cmd /c 'MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log'
已安装并生成了日志。但是,发生错误。以下是日志中产生错误的区域周围的片段:
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 ===
根据下面的一些评论,我已尝试 运行 在不同的系统上执行上述命令,因为 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.
如您所述,安静(无人值守,no-UI)安装需要从 提升的 会话中进行 运行ning。
在 PowerShell remoting via
Invoke-Command
-ComputerName
的上下文中,远程会话 自动且总是 运行 具有提升- 假设目标用户是远程计算机上BUILTIN\Administrators
组的成员。
因此,尝试如下操作(假设当前用户是目标机器的管理员):
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." }
}
到 运行 local 机器上的安装程序 - 来自 elevated 会话 - 只需 运行直接来自上面脚本块的命令,即:
# 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'
或在 PS 5(作为管理员):
install-package gh_2.10.1_windows_amd64.msi
遗憾的是,-additionalarguments 参数不起作用。