Add a script for forcibly installing winget

This commit is contained in:
Manuel Thalmann 2024-03-13 09:06:48 +01:00
parent 837ec6df1a
commit 554f3c9a63

View file

@ -0,0 +1,39 @@
#!/bin/pwsh
. "$PSScriptRoot/../../Scripts/Context.ps1";
function Install-Winget {
param([Context] $context)
Write-Host "Installing winget";
$namePattern = "*Desktop*Installer*";
[System.Collections.Generic.List[string]] $packages = @();
$versions = Get-AppxPackage -AllUsers "$namePattern";
if ($versions.Count -gt 0) {
if (-not $(Get-Command sqlite3)) {
$packages.Add("sqlite");
}
if ($packages.Count -gt 0) {
Write-Host "Installing prequisites for uninstalling winget";
foreach ($package in $packages) {
choco install -y "$package";
}
}
foreach ($version in $versions) {
sqlite3 `
"$env:ProgramData\Microsoft\Windows\AppRepository\StateRepository-Machine.srd" `
"UPDATE Package SET IsInbox = 0 WHERE PackageFullName = '$($version.PackageFullName)'";
}
Get-AppxPackage -AllUsers "$namePattern" | Remove-AppxPackage -AllUsers;
Get-AppxProvisionedPackage -Online | `
Where-Object { $_.DisplayName -like "$namePattern" } | `
Remove-AppxProvisionedPackage -Online;
}
choco install -y winget;
}