Sep 29 2022 07:38 AM - edited Sep 30 2022 08:16 AM
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. The script will say the device has issues and fix the issue, but it will actually say fixed and still have not removed the applications.
DETECT SCRIPT
#Detect built-in applications not needed for organisation devices
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
foreach ($App In $AppPackages)
{
$Package = Get-AppxPackage | Where-Object {$_.Name -eq $App}
$ProvisionedPackage = Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -eq $App}
If ($null -ne $Package) {
Write-Host "App Found Start remediation script"
$found = $true
} Else {
Write-Host "Package $App not found"
}
If ($null -ne $ProvisionedPackage) {
Write-Host "App Found Start remediation script"
$found = $true
} Else {
Write-Host "Provisioned Package $App not found"
}
}
If ($found)
{
exit 1
}
Else {
exit 0
}
}
catch
{
$errMsg = $_.Exception.Message
Write-Error $errMsg
exit 1
}
REMEDIATION SCRIPT
#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) {
$Package = Get-AppxPackage | Where-Object {$_.Name -eq $App}
$ProvisionedPackage = Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -eq $App}
If ($Package -ne $null) {
Write-Host "Removing Package : $App"
Remove-AppxPackage -Package $Package.PackageFullName
}
Else {
Write-Host "Package $App not found"
}
If ($ProvisionedPackage -ne $null) {
Write-Host "Removing ProvisionedPackage : $App"
Remove-AppxProvisionedPackage -online -Packagename $ProvisionedPackage.Packagename
}
Else {
Write-Host "Provisioned Package $App not found"
}
}
* Fix was to add -AllUsers
Sep 30 2022 08:16 AM
SolutionOct 05 2022 09:49 AM
@JimmyWork Can you please post full version of the scripts, including "-AllUsers"?
Oct 05 2022 10:15 AM
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
Oct 06 2022 01:05 AM
@JimmyWork Thanks! I'll give it a try today
Oct 06 2022 06:57 AM
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
Sep 30 2022 08:16 AM
Solution