Add a script for forcibly installing winget
This commit is contained in:
parent
837ec6df1a
commit
554f3c9a63
1 changed files with 39 additions and 0 deletions
39
scripts/Windows/Software/winget/Install.ps1
Normal file
39
scripts/Windows/Software/winget/Install.ps1
Normal 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;
|
||||
}
|
||||
|
Loading…
Reference in a new issue