我相信大部分同学都能找到文档在server2019上安装上winget
几乎同样的办法、同样的安装文件,安装完后,server2022打开命令行敲winget能识别命令,server2019却不行,如何解决?
代码语言:powershell复制Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module NtObjectManager -Force
$installationPath = (Get-AppxPackage Microsoft.DesktopAppInstaller).InstallLocation
Set-ExecutionAlias -Path "C:WindowsSystem32winget.exe" -PackageName "Microsoft.DesktopAppInstaller_8wekyb3d8bbwe" -EntryPoint "Microsoft.DesktopAppInstaller_8wekyb3d8bbwe!winget" -Target "$installationPathwinget.exe" -AppType Desktop -Version 3
这段修复代码我是参考了2个文档上的代码后恍然大悟的(要会甄别,去伪存真),其中也杂糅了我自己的优化
https://github.com/al-cheb/winget_install_script/blob/main/Install-WinGet.ps1
https://www.andreasnick.com/113-winget-on-server-2019.html
代码中安装的NtObjectManager模块引入了Set-ExecutionAlias和Get-ExecutionAlias