Created
November 18, 2020 23:07
-
-
Save jameseleach/a0cae423a1093ff8be2235693ab8fab3 to your computer and use it in GitHub Desktop.
Uninstall Windows Store Apps
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
param ( | |
[System.String]$LogFile = "C:\Temp\IntuneLogs\WindowsAppsUninstall.log", | |
$apps = ( | |
"Microsoft.3DBuilder", | |
"Microsoft.BingWeather", | |
"Microsoft.Messaging", | |
"Microsoft.Microsoft3DViewer", | |
"Microsoft.MicrosoftOfficeHub", | |
"Microsoft.MicrosoftSolitaireCollection", | |
"Microsoft.MixedReality.Portal", | |
"Microsoft.MSPaint", | |
"Microsoft.Office.OneNote", | |
"Microsoft.OneConnect", | |
"Microsoft.People", | |
"Microsoft.Print3D", | |
"Microsoft.SkypeApp", | |
"Microsoft.StorePurchaseApp", | |
"Microsoft.Wallet", | |
"microsoft.windowscommunicationsapps", | |
"Microsoft.Xbox.TCUI", | |
"Microsoft.XboxApp", | |
"Microsoft.XboxGameOverlay", | |
"Microsoft.XboxGamingOverlay", | |
"Microsoft.XboxIdentityProvider", | |
"Microsoft.XboxSpeechToTextOverlay", | |
"Microsoft.YourPhone", | |
"Microsoft.ZuneMusic", | |
"Microsoft.ZuneVideo" | |
) | |
) | |
function Get-TimeStamp { | |
return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date -OutVariable:$Null) | |
} | |
# Create log file | |
if (Test-Path -Path $LogFile) { | |
# File exists | |
} else { | |
[void](New-Item -Path $LogFile -Force) | |
} | |
Add-Content -Path $LogFile -Value "$(Get-TimeStamp) [INFO] --- START OF SESSION ---" | |
foreach ($app in $apps) { | |
$Packages = Get-AppxPackage -PackageTypeFilter Main, Bundle, Resource -AllUsers -Name $app | |
foreach ($Package in $Packages) { | |
if ("Installed" -in $Package.PackageUserInformation.InstallState) { | |
Add-Content -Path $LogFile -Value "$(Get-TimeStamp) [INFO] $app is installed. Attempting uninstall." | |
try { | |
Remove-AppxPackage -Package $Package -ErrorAction Stop | |
} catch { | |
$ErrorMsg = New-Object ComponentModel.Win32Exception ("$(Get-TimeStamp) [ERROR] " + $PSItem.Exception) | |
Add-Content -Path $LogFile -Value $ErrorMsg | |
Write-Error -Message $ErrorMsg | |
throw $ErrorMsg | |
} | |
} else { | |
Add-Content -Path $LogFile -Value "$(Get-TimeStamp) [INFO] $app is not installed. Uninstallation not necessary." | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment