Forum Discussion
JimmyWork
Sep 29, 2022Iron Contributor
Remediation script says it worked but did not actually remove applications
The following works when you run it local on the computer. It also works if it is package as a win32 app and ran at deployment during Autopilot. It however does not work as a remediation script....
- Sep 30, 2022Adding -AllUsers to both Get and Remove-AppxPackage fixed the issue
PhilSheppard
Copper Contributor
JimmyWork Can you please post full version of the scripts, including "-AllUsers"?
JimmyWork
Oct 05, 2022Iron Contributor
This is the current version, not finished with detect script. This is my co-workers code not mine so I don't take any credit here.
#Uninstalls built-in applications not needed for organisation devices
# List of Applications to Remove
$AppPackages = @()
$AppPackages += 'Microsoft.Xbox.TCUI'
$AppPackages += 'Microsoft.XboxApp'
$AppPackages += 'Microsoft.XboxGamingOverlay'
$AppPackages += 'Microsoft.XboxIdentityProvider'
$AppPackages += 'Microsoft.XboxSpeechToTextOverlay'
$AppPackages += 'Microsoft.GamingApp'
$AppPackages += 'Microsoft.SkypeApp'
$AppPackages += 'MicrosoftTeams'
$AppPackages += 'Microsoft.ZuneMusic'
$AppPackages += 'Microsoft.ZuneVideo'
$AppPackages += 'Microsoft.WindowsFeedbackHub'
$AppPackages += 'Microsoft.549981C3F5F10'
$AppPackages += 'Microsoft.BingNews'
$AppPackages += 'Microsoft.BingWeather'
$AppPackages += 'Microsoft.MicrosoftSolitaireCollection'
$AppPackages += 'Microsoft.WindowsMaps'
$AppPackages += 'Microsoft.GetStarted'
$AppPackages += 'Microsoft.People'
$AppPackages += 'Microsoft.windowscommunicationsapps'
$AppPackages += 'Microsoft.Messaging'
$AppPackages += 'Microsoft.MixedReality.Portal'
$AppPackages += 'Microsoft.YourPhone'
$AppPackages += 'Microsoft.OneConnect'
$Error.Clear()
foreach ($App In $AppPackages)
{
try {
Write-Host "+ Removing AppX Package: $App"
Get-AppxPackage AllUsers -PackageTypeFilter Main,Bundle,Resource,Framework | Where-Object {$_.Name -eq $App } | Remove-AppxPackage -AllUsers
Write-Host "+ Removing Provisioned Package: $App"
Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -eq $App} | Remove-AppxProvisionedPackage -Online -AllUsers
Write-Host ""
}
catch {
Write-Host "** ERROR ** Failed to remove: $App **"
Write-Host "ERROR: at $($_.InvocationInfo.ScriptLineNumber)"
Write-Error "Message: " $_.Exception.Message
Write-Host "StackTrace: "
Write-Host $_.Exception.StackTrace
Write-Host ""
exit 1
}
}
exit 0
- PhilSheppardOct 06, 2022Copper Contributor
JimmyWork Thanks! I'll give it a try today
- JimmyWorkOct 06, 2022Iron Contributor
The script contained a type, here is the full detection and remediation script. again this is my co-worker not my script so no credit to me 🙂Detection
<# .SYNOPSIS Detection script for built-in Microsoft applications .DESCRIPTION Checks if pre-defined default Microsoft applications are installed. If found then 'exit 1' is returned that informs endpoint that 'errors' where found and that a connected remiditation script should be run. .NOTES To be used in the Endpoint Manager and as the detection script #> try { # List of Applications to Remove $AppPackages = @() $AppPackages += 'Microsoft.Xbox.TCUI' $AppPackages += 'Microsoft.XboxApp' $AppPackages += 'Microsoft.XboxGamingOverlay' $AppPackages += 'Microsoft.XboxIdentityProvider' $AppPackages += 'Microsoft.XboxSpeechToTextOverlay' $AppPackages += 'Microsoft.GamingApp' $AppPackages += 'Microsoft.SkypeApp' $AppPackages += 'MicrosoftTeams' $AppPackages += 'Microsoft.ZuneMusic' $AppPackages += 'Microsoft.ZuneVideo' $AppPackages += 'Microsoft.WindowsFeedbackHub' $AppPackages += 'Microsoft.549981C3F5F10' $AppPackages += 'Microsoft.BingNews' $AppPackages += 'Microsoft.BingWeather' $AppPackages += 'Microsoft.MicrosoftSolitaireCollection' $AppPackages += 'Microsoft.WindowsMaps' $AppPackages += 'Microsoft.GetStarted' $AppPackages += 'Microsoft.People' $AppPackages += 'Microsoft.windowscommunicationsapps' $AppPackages += 'Microsoft.Messaging' $AppPackages += 'Microsoft.MixedReality.Portal' $AppPackages += 'Microsoft.YourPhone' $AppPackages += 'Microsoft.OneConnect' $Error.Clear() $found = $false Write-Host "------- Detection Script - Uninstall Builtin Applications -------" foreach ($App In $AppPackages) { $Package = Get-AppxPackage -AllUsers -PackageTypeFilter Main,Bundle,Resource,Framework | Where-Object {$_.Name -eq $App } $ProvisionedPackage = Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -eq $App} if ($null -ne $Package) { Write-Host "+ AppX Package Found: $App" $found = $true } else { Write-Host "+ AppX Package NOT Found: $App" } if ($null -ne $ProvisionedPackage) { Write-Host "+ Provision Package Found: $App" $found = $true } else { Write-Host "+ Provisioned Package NOT Found: $App" } Write-Host "" } If ($found) { Write-Host "Found packages, triggering remidation script" exit 1 } Else { Write-Host "No packages found" exit 0 } } catch { $errMsg = $_.Exception.Message Write-Error $errMsg exit 1 } finally { Write-Host "------- END - Detection Script - Uninstall Builtin Applications -------" }
Remediation
<# .SYNOPSIS Remidiation script for built-in Microsoft applications .DESCRIPTION Remidiates (unistalls) pre-defined default Microsoft applications. .NOTES To be used in the Endpoint Manager and as the remidiation script #> # List of Applications to Remove $AppPackages = @() $AppPackages += 'Microsoft.Xbox.TCUI' $AppPackages += 'Microsoft.XboxApp' $AppPackages += 'Microsoft.XboxGamingOverlay' $AppPackages += 'Microsoft.XboxIdentityProvider' $AppPackages += 'Microsoft.XboxSpeechToTextOverlay' $AppPackages += 'Microsoft.GamingApp' $AppPackages += 'Microsoft.SkypeApp' $AppPackages += 'MicrosoftTeams' $AppPackages += 'Microsoft.ZuneMusic' $AppPackages += 'Microsoft.ZuneVideo' $AppPackages += 'Microsoft.WindowsFeedbackHub' $AppPackages += 'Microsoft.549981C3F5F10' $AppPackages += 'Microsoft.BingNews' $AppPackages += 'Microsoft.BingWeather' $AppPackages += 'Microsoft.MicrosoftSolitaireCollection' $AppPackages += 'Microsoft.WindowsMaps' $AppPackages += 'Microsoft.GetStarted' $AppPackages += 'Microsoft.People' $AppPackages += 'Microsoft.windowscommunicationsapps' $AppPackages += 'Microsoft.Messaging' $AppPackages += 'Microsoft.MixedReality.Portal' $AppPackages += 'Microsoft.YourPhone' $AppPackages += 'Microsoft.OneConnect' $Error.Clear() foreach ($App In $AppPackages) { try { Write-Host "+ Removing AppX Package: $App" Get-AppxPackage -AllUsers -PackageTypeFilter Main,Bundle,Resource,Framework | Where-Object {$_.Name -eq $App } | Remove-AppxPackage -AllUsers Write-Host "+ Removing Provisioned Package: $App" Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -eq $App} | Remove-AppxProvisionedPackage -Online -AllUsers Write-Host "" } catch { Write-Host "** ERROR ** Failed to remove: $App **" Write-Host "ERROR: at $($_.InvocationInfo.ScriptLineNumber)" Write-Error "Message: " $_.Exception.Message Write-Host "StackTrace: " Write-Host $_.Exception.StackTrace Write-Host "" exit 1 } } exit 0