wingetautoupdate/Winget-AutoUpdate/functions/Update-StoreApps.ps1

30 lines
964 B
PowerShell
Raw Normal View History

2023-10-12 02:22:15 +00:00
#Function to force an upgrade of Store Apps
Function Update-StoreApps ($Log = $false) {
2023-10-12 17:42:01 +00:00
$force_string = "-> Forcing an upgrade of Store Apps (this can take a minute)..."
$fail_string = "-> ...something went wrong!"
2023-10-12 02:22:15 +00:00
#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) {
2023-10-12 17:42:01 +00:00
$true {Write-ToLog $force_string "yellow"}
Default {Write-Host $force_string -ForegroundColor Yellow}
2023-10-12 02:22:15 +00:00
}
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) {
2023-10-12 17:42:01 +00:00
$true {Write-ToLog $fail_string "red"}
Default {Write-Host $fail_string -ForegroundColor Red}
2023-10-12 02:22:15 +00:00
}
return $false
}
}
}