Skip to main content

Remove PUA

Summary

This script manages the removal of predefined bloatware packages or lists installed bloatware based on a centrally maintained list. It offers three primary operations: bulk removal, selective removal, and bloatware listing. The remove parameter allows bypassing the PUA List to remove any installed AppxPackage.

PUA List: https://content.provaltech.com/attachments/potentially-unwanted-applications.json

Sample Run

Sample Run 1

To get the list of installed Bloatware:
Sample Run 2

To remove all installed Bloatware installed on the computer from the PUA List:
Sample Run 3

To remove all installed Bloatware except any of WindowsStoreApps category apps and Microsoft.BingNews, and Microsoft.MSPaint:
Sample Run 4

To remove individual AppxPackages installed on the machine like Microsoft.MicrosoftOfficeHub, Microsoft.XboxApp, Microsoft.Messaging, and Microsoft.People:
Sample Run 5

Sample Run 6

Dependencies

Remove-PUA

Implementation

Script Details

Step 1

Navigate to AutomationTasks
step1

Step 2

Create a new Script Editor style task by choosing the Script Editor option from the Add dropdown menu
step2

The New Script page will appear on clicking the Script Editor button:
step3

Step 3

Fill in the following details in the Description section:

Name: Remove - PUA
Description:

This script manages the removal of predefined bloatware packages or lists installed bloatware based on a centrally maintained list. It offers three primary operations: bulk removal, selective removal, and bloatware listing. The remove parameter allows bypassing the PUA List to remove any installed AppxPackage. 

PUA List: https://content.provaltech.com/attachments/potentially-unwanted-applications.json

Category: Application

Task Detail

Parameters

ListBloatware

Add a new parameter by clicking the Add Parameter button present at the top-right corner of the screen.
Add  Parameter 1

This screen will appear.
Add Parameter 2

  • Set ListBloatware in the Parameter Name field.
  • Select Flag from the Parameter Type dropdown menu.
  • Click the Save button.
    Add Parameter 3

Remove

Add a new parameter by clicking the Add Parameter button present at the top-right corner of the screen.
Add  Parameter 1

This screen will appear.
Add Parameter 2

  • Set Remove in the Parameter Name field.
  • Select Text String from the Parameter Type dropdown menu.
  • Click the Save button.
    Add Parameter 6

RemoveAll

Add a new parameter by clicking the Add Parameter button present at the top-right corner of the screen.
Add  Parameter 1

This screen will appear.
Add Parameter 2

  • Set RemoveAll in the Parameter Name field.
  • Select Flag from the Parameter Type dropdown menu.
  • Click the Save button.
    Add Parameter 9

Category

Add a new parameter by clicking the Add Parameter button present at the top-right corner of the screen.
Add  Parameter 1

This screen will appear.
Add Parameter 2

  • Set Category in the Parameter Name field.
  • Select Text String from the Parameter Type dropdown menu.
  • Click the Save button.
    Add Parameter 12

Except

Add a new parameter by clicking the Add Parameter button present at the top-right corner of the screen.
Add  Parameter 1

This screen will appear.
Add Parameter 2

  • Set Except in the Parameter Name field.
  • Select Text String from the Parameter Type dropdown menu.
  • Click the Save button.
    Add Parameter 15

Script Editor

Click the Add Row button in the Script Editor section to start creating the script
AddRow

A blank function will appear.
Add Row continued

Row 1: Function: PowerShell Script

Search and select the PowerShell Script function.

Row 1 Image 1

The following function will pop up on the screen:
Row 1 Image 2

Paste in the following PowerShell script and set the Expected time of script execution in seconds to 3600 seconds. Click the Save button.

#region user parameters
$ListBloatware = '@ListBloatware@'
$Remove = '@Remove@'
$RemoveAll = '@RemoveAll@'
$Category = '@Category@'
$Except = '@Except@'

if ($ListBloatware -match '1|True|Yes') {
$ListBloatware = $true
} else {
$ListBloatware = $false
}

if ($Remove -and $Remove -notmatch 'Remove' -and $Remove -match '[A-z]') {
$Remove = $Remove -replace ', ', ',' -replace ' ,', ','
$Remove = $Remove.Trim()
$Remove = $Remove.Split(',')
}

if ($RemoveAll -match '1|True|Yes') {
$RemoveAll = $true
} else {
$RemoveAll = $false
}

if ($RemoveAll -and $Category -and $Category -notmatch 'Category' -and $Category -match '[A-z]') {
if (!(('MsftBloatApps', 'ThirdPartyBloatApps') -contains $Category)) {
throw 'Invalid category. Supported categories are: MsftBloatApps, and ThirdPartyBloatApps'
} else {
$Category = $Category
}
} else {
$Category = $false
}

if ($RemoveAll -and $Except -and $Except -notmatch 'Except' -and $Except -match '[A-z]') {
$Except = $Except -replace ', ', ',' -replace ' ,', ','
$Except = $Except.Trim()
$Except = $Except.Split(',')
} else {
$Except = $false
}
#endregion

#region parameters hash table
$Parameters = @{}
if ( $ListBloatware ) {
$Parameters.Add('ListBloatware', $true)
} elseif ( $Remove ) {
$Parameters.Add('Remove', $Remove)
} elseif ( $RemoveAll ) {
$Parameters.Add('RemoveAll', $true)
if ( $Category ) {
$Parameters.Add('Category', $Category)
}
if ( $Except ) {
$Parameters.Add('Except', $Except)
}
} else {
throw 'Invalid parameter set.'
}
#endregion

#region variables
[Net.ServicePointManager]::SecurityProtocol = [enum]::ToObject([Net.SecurityProtocolType], 3072)
$ProjectName = 'Remove-PUA'
$BaseURL = 'https://file.provaltech.com/repo'
$PS1URL = "$BaseURL/script/$ProjectName.ps1"
$WorkingDirectory = "C:\ProgramData\_automation\script\$ProjectName"
$PS1Path = "$WorkingDirectory\$ProjectName.ps1"
$Workingpath = $WorkingDirectory
$LogPath = "$WorkingDirectory\$ProjectName-log.txt"
$ErrorLogPath = "$WorkingDirectory\$ProjectName-Error.txt"
#endregion

#region Setup - Folder Structure
New-Item -Path $WorkingDirectory -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
$response = Invoke-WebRequest -Uri $PS1URL -UseBasicParsing
if (($response.StatusCode -ne 200) -and (!(Test-Path -Path $PS1Path))) {
Write-Error -Message "No pre-downloaded script exists and the script '$PS1URL' failed to download. Exiting."
return
} elseif ($response.StatusCode -eq 200) {
Remove-Item -Path $PS1Path -ErrorAction SilentlyContinue
[System.IO.File]::WriteAllLines($PS1Path, $response.Content)
}
if (!(Test-Path -Path $PS1Path)) {
Write-Error -Message 'An error occurred and the script was unable to be downloaded. Exiting.'
return
}
#endregion

& $PS1Path @Parameters
#region Execution
if ($Parameters) {
& $PS1Path @Parameters
} else {
& $PS1Path
}
#endregion

if ( !(Test-Path $LogPath) ) {
throw 'PowerShell Failure. A Security application seems to have restricted the execution of the PowerShell Script.'
}
if ( Test-Path $ErrorLogPath ) {
$ErrorContent = ( Get-Content -Path $ErrorLogPath )
throw $ErrorContent
}
Get-Content -Path $LogPath

Row 1 Image 3

Row 2: Function: Script Log

Add a new row by clicking the Add Row button.
AddRow

A blank function will appear.
Row 2 Image 2

Search and select the Script Log function.
Row 2 Image 3

Row 2 Image 4

The following function will pop up on the screen:
Row 2 Image 5

In the script log message, simply type %output% and click the Save button
Row 2 Image 6

Click the Save button at the top-right corner of the screen to save the script.
Row 2 Image 8

Completed Script

Row 3 Image 1

Output

  • Script log