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

33 lines
1.1 KiB
PowerShell
Raw Normal View History

2023-10-12 02:22:15 +00:00
#Function to force an upgrade of Store Apps
2023-10-17 20:35:36 +00:00
Function Update-StoreApps {
2023-10-12 02:22:15 +00:00
2023-10-23 02:47:22 +00:00
$info_string = "-> Forcing an upgrade of Store Apps..."
$action_string = "-> ...this can take a minute!"
2023-10-12 17:42:01 +00:00
$fail_string = "-> ...something went wrong!"
2023-10-23 02:47:22 +00:00
$irrelevant_string = "-> ...WAU is running on WSB (Windows Sandbox) or Windows Server - Microsoft Store is not available!"
Write-ToLog $info_string "yellow"
2023-10-12 17:42:01 +00:00
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") {
2023-10-17 20:35:36 +00:00
2023-10-12 02:22:15 +00:00
try {
# Can't get it done with Get-CimInstance, using deprecated Get-WmiObject
2023-10-12 02:22:15 +00:00
$namespaceName = "root\cimv2\mdm\dmmap"
$className = "MDM_EnterpriseModernAppManagement_AppManagement01"
$wmiObj = Get-WmiObject -Namespace $namespaceName -Class $className
2023-10-23 02:47:22 +00:00
Write-ToLog $action_string "green"
2023-10-12 02:22:15 +00:00
$wmiObj.UpdateScanMethod() | Out-Null
return $true
}
catch {
2023-10-17 20:35:36 +00:00
Write-ToLog $fail_string "red"
2023-10-12 02:22:15 +00:00
return $false
}
}
2023-10-21 04:20:00 +00:00
else {
2023-10-23 02:47:22 +00:00
Write-ToLog $irrelevant_string "yellow"
2023-10-21 04:20:00 +00:00
}
2023-10-12 02:22:15 +00:00
}