Windows 10 1703 – Remove Universal Windows Platform (UWP) Apps

DON’T Do THIS! Use AppLocker instead! Do not remove any apps from the image

Hi reader,

I would like to share my script to remove windows universal apps, which I have tried to make it simple as possible.
First let me explain, that there seems to exist two different types of Apps which reside within the Windows 10 Image. You can list them with Get-AppxPackage and Get-AppxProvisionedPackage (you need Administrator permission to do so):

And both of those Apps require a different Powershell command to remove the App. For the provisioned UWP Apps, you need to use Remove-AppxProvisionedPackage (Technet Source). The other UWP Apps can be removed with Remove-AppxPackage (TechNet Source).

This was leading me to create a Powershell Script, where you can easily create Output Files of the Apps. Afterwards you can edit the output files, and use them as Input File to remove the apps from the system.
The following command is required, to export the provisoned Apps:
.\ManageUWPApps.ps1 -ScriptFunction Export
The Script will generate a csv called ProvisionedApps.txt where the powershell Script resides, unless you had defined the parameter -Workfile (See Script Description for more Information).
You can then delete all the Apps, which should reside on the system, and only include Apps, which should get removed. In the following example, only OneNote and the Wallet gets removed:

To remove the provisioned Apps within the csv, you have to start the Script with different parameters:
.\ManageUWPApps.ps1 -ScriptFunction RemoveApps -WorkFile 'C:\temp\ProvisionedApps.txt'

For the other apps, to export you need to use ExportApps:
.\ManageUWPApps.ps1 -ScriptFunction ExportApps
This will create an output file named AllOtherApps.txt, unless specified with the Workfile parameter.

To remove the Apps, edit the exported List as above, and use the File as import file within the following command:
.\ManageUWPApps.ps1 -ScriptFunction RemoveOtherApps -WorkFile 'C:\temp\AllOtherApps.txt'

You can download the Script from my OneDrive, or you can try copy/paste from blog (be aware of special Chars) at the end of this blog.
Download Link txt: https://1drv.ms/t/s!Aq0GcVCqC0Rlor0FIqoDPUF2ghrbrA

Hope this helps.

The Script:
# Description
#-> For Exports: Existing Files with same Name will be overwritten!

# Export Examples:
# .\ManageUWPApps.ps1 -ScriptFunction Export
# -> This will export the provisioned Apps to a CSV File located where the Powershell Script resides, at it will overwrite an existent File named ProvisionedApps.txt
#
# .\ManageUWPApps.ps1 -ScriptFunction Export -WorkFile c:\temp\11111.txt
# -> This will export the provisioned Apps to a CSV File located at c:\temp\11111.txt, at it will overwrite an existent File
#
# The paramter switch “ExportApps” works as above
# .\ManageUWPApps.ps1 -ScriptFunction ExportApps
# -> This will export the other Apps to a CSV File located where the Powershell Script resides, at it will overwrite an existent File named AllOtherApps.txt

# Remove Apps Examples
# .\ManageUWPApps.ps1 -ScriptFunction RemoveApps -WorkFile ‘C:\temp\ProvisionedAppx.txt’
# -> This will remove all provisioned Apps which reside in the omitted text file (same layout as export required!)
#
# .\ManageUWPApps.ps1 -ScriptFunction RemoveOtherApps -WorkFile ‘C:\temp\AllOtherApps.txt’
# -> This will remove all other Apps which reside in the omitted text file (same layout as export required!)

#See blog: https://blog.hosebei.ch to be created 🙂

#### Require Parameters

#Force to use Selection of Execution
Param(
[Parameter(mandatory=$true)][string]$ScriptFunction,
[string]$WorkFile
)

#### Functions

#Create OutPutFile Function
Function Create-OutPutFile {
Param(
[string]$OutPutFile
)

if($OutPutFile -eq “”) {
Write-Error “No OutpuFile Name was ommited or generated. Script aborted”
exit(1)
}

#Export Provisioned Apps
$apps = Get-AppxProvisionedPackage -Online | select DisplayName,PackageName
#Delete Export File if already existent
if(Test-Path $OutPutFile) {
Remove-Item $OutPutFile -Force
}
$apps | export-csv -Path $OutPutFile -Delimiter “,” -NoTypeInformation

}

#Creat Export file for Apps
Function Create-OutPutFileApps {
Param(
[string]$OutPutFile
)

if($OutPutFile -eq “”) {
Write-Error “No OutpuFile Name was ommited or generated. Script aborted”
exit(4)
}

#Export Provisioned Apps
$apps = Get-AppxPackage -AllUsers | select Name,PackageFullName
#Delete Export File if already existent
if(Test-Path $OutPutFile) {
Remove-Item $OutPutFile -Force
}
$apps | export-csv -Path $OutPutFile -Delimiter “,” -NoTypeInformation

}

#Remove Provisionied Apps Function
Function Remove-ProvisionedApps {

Param(
[string]$InPutFile
)

if(Test-Path $InPutFile) {
$workfile = $InPutFile
}
else {
Write-Warning “Input File was not accessible! The following file name was tried:”
Write-Warning $InPutFile
exit(3)
}

#read input file
$AppsToRemove = import-csv -Path $workfile -Delimiter “,”

#execute appx removal
foreach($appToRemove in $AppsToRemove){

Write-Host (“The following app will be removed: ” + $appToRemove.DisplayName)
Remove-AppxProvisionedPackage -Online -AllUsers -PackageName $appToRemove.PackageName

}

}

Function Remove-AllOtherApps {
Param(
[string]$InPutFile
)

if(Test-Path $InPutFile) {
$workfile = $InPutFile
}
else {
Write-Warning “Input File was not accessible! The following file name was tried:”
Write-Warning $InPutFile
exit(7)
}

#read input file
$AppsToRemove = import-csv -Path $workfile -Delimiter “,”

#execute appx removal
foreach($appToRemove in $AppsToRemove){

Write-Host (“The following app will be removed: ” + $appToRemove.Name)
Remove-AppxPackage -AllUsers -Package $appToRemove.PackageFullName

}

}

#### Main Script

#Main Script Switch Section
switch ($ScriptFunction) {

“Export” {
#Check if WorkFile was defined
if($WorkFile -eq “”) {
#Generate Workfile Path
$WorkFile = $PSScriptRoot + “\ProvisionedApps.txt”

}
#Start Export
Create-OutPutFile -OutPutFile $WorkFile
}

“ExportApps” {
#Check if WorkFile was defined
if($WorkFile -eq “”) {
#Generate Workfile Path
$WorkFile = $PSScriptRoot + “\AllOtherApps.txt”

}
#Start Export
Create-OutPutFileApps -OutPutFile $WorkFile
}

“RemoveApps” {
#Check for Input File
if($WorkFile -eq “”) {
#Generate Workfile Path
Write-Warning “You must provide the InputFile Path when removing provosionied apps!”
Write-Warning “Example: ManageUWPApps.ps1 -ScriptFunction RemoveApps -WorkFile ‘C:\temp\ProvisionedAppx.txt'”
exit(2)

}
else {
Remove-ProvisionedApps -InPutFile $WorkFile
}

}

“RemoveOtherApps” {
#Check for Input File
if($WorkFile -eq “”) {
#Generate Workfile Path
Write-Warning “You must provide the InputFile Path when removing provosionied apps!”
Write-Warning “Example: ManageUWPApps.ps1 -ScriptFunction RemoveOtherApps -WorkFile ‘C:\temp\AllOtherAppx.txt'”
exit(6)

}
else {
Remove-AllOtherApps -InPutFile $WorkFile
}

}

default {write-host “See description at top of the script, and/or visit my blog”}

}

2 thoughts on “Windows 10 1703 – Remove Universal Windows Platform (UWP) Apps

  1. Thanks for this script and I have tested this but this is not removing apps for other logged on users as it just removing apps from current user only.

    Please help to remove apps from different profiles as well…Looking forward to your reply.

    • In my case, the adobe app was removed. But yes, you might consider other results.
      It is anyway more recommended to use applocker to restrict apps (as far as I remeber from ignite…)

Leave a Reply to Martin Wüthrich Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.