-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #419 from KnifMelti/Update-Winget
Better Functions
- Loading branch information
Showing
5 changed files
with
103 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#Function to force an upgrade of Store Apps | ||
|
||
Function Update-StoreApps ($Log = $false) { | ||
|
||
$force_string = "-> Forcing an upgrade of Store Apps (this can take a minute)..." | ||
$fail_string = "-> ...something went wrong!" | ||
|
||
#If not WSB or Server, upgrade Microsoft Store Apps! | ||
if (!(Test-Path "${env:SystemDrive}\Users\WDAGUtilityAccount") -and (Get-CimInstance Win32_OperatingSystem).Caption -notmatch "Windows Server") { | ||
switch ($Log) { | ||
$true {Write-ToLog $force_string "yellow"} | ||
Default {Write-Host $force_string -ForegroundColor Yellow} | ||
} | ||
try { | ||
$namespaceName = "root\cimv2\mdm\dmmap" | ||
$className = "MDM_EnterpriseModernAppManagement_AppManagement01" | ||
$wmiObj = Get-WmiObject -Namespace $namespaceName -Class $className | ||
$wmiObj.UpdateScanMethod() | Out-Null | ||
return $true | ||
} | ||
catch { | ||
switch ($Log) { | ||
$true {Write-ToLog $fail_string "red"} | ||
Default {Write-Host $fail_string -ForegroundColor Red} | ||
} | ||
return $false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#Function to download and update WinGet | ||
|
||
Function Update-WinGet ($WinGetAvailableVersion, $DownloadPath, $Log = $false) { | ||
|
||
$download_string = "-> Downloading WinGet MSIXBundle for App Installer..." | ||
$install_string = "-> Installing WinGet MSIXBundle for App Installer..." | ||
$success_string = "-> WinGet MSIXBundle (v$WinGetAvailableVersion) for App Installer installed successfully" | ||
$reset_string = "-> WinGet sources reset." | ||
$fail_string = "-> Failed to intall WinGet MSIXBundle for App Installer..." | ||
|
||
#Download WinGet MSIXBundle | ||
switch ($Log) { | ||
$true {Write-ToLog $download_string} | ||
Default {Write-Host $download_string} | ||
} | ||
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$WinGetAvailableVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" | ||
$WebClient = New-Object System.Net.WebClient | ||
$WebClient.DownloadFile($WinGetURL, "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle") | ||
|
||
#Install WinGet MSIXBundle in SYSTEM context | ||
try { | ||
switch ($Log) { | ||
$true {Write-ToLog $install_string} | ||
Default {Write-Host $install_string} | ||
} | ||
Add-AppxProvisionedPackage -Online -PackagePath "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null | ||
switch ($Log) { | ||
$true {Write-ToLog $success_string "green"} | ||
Default {Write-host $success_string -ForegroundColor Green} | ||
} | ||
|
||
#Reset WinGet Sources | ||
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') } | ||
if ($ResolveWingetPath) { | ||
switch ($Log) { | ||
$true {Write-ToLog $reset_string "green"} | ||
Default {Write-Host $reset_string -ForegroundColor Green} | ||
} | ||
#If multiple version, pick last one | ||
$WingetPath = $ResolveWingetPath[-1].Path | ||
& $WingetPath source reset --force | ||
} | ||
} | ||
catch { | ||
switch ($Log) { | ||
$true {Write-ToLog $fail_string "red"} | ||
Default {Write-Host $fail_string -ForegroundColor Red} | ||
} | ||
Update-StoreApps | ||
} | ||
|
||
#Remove WinGet MSIXBundle | ||
Remove-Item -Path "$DownloadPath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue | ||
} |