Skip to content

Instantly share code, notes, and snippets.

@loopyd
Forked from mark05e/Remove-HPbloatware.ps1
Created August 5, 2023 04:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loopyd/07a7242ece52793c29947481324822c6 to your computer and use it in GitHub Desktop.
Save loopyd/07a7242ece52793c29947481324822c6 to your computer and use it in GitHub Desktop.
Remove HP bloatware
# ██████╗ ███████╗███╗ ███╗ ██████╗ ██╗ ██╗███████╗ ██╗ ██╗██████╗
# ██╔══██╗██╔════╝████╗ ████║██╔═══██╗██║ ██║██╔════╝ ██║ ██║██╔══██╗
# ██████╔╝█████╗ ██╔████╔██║██║ ██║██║ ██║█████╗ ███████║██████╔╝
# ██╔══██╗██╔══╝ ██║╚██╔╝██║██║ ██║╚██╗ ██╔╝██╔══╝ ██╔══██║██╔═══╝
# ██║ ██║███████╗██║ ╚═╝ ██║╚██████╔╝ ╚████╔╝ ███████╗ ██║ ██║██║
# ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚══════╝ ╚═╝ ╚═╝╚═╝
#
# ██████╗ ██╗ ██████╗ █████╗ ████████╗██╗ ██╗ █████╗ ██████╗ ███████╗
# ██╔══██╗██║ ██╔═══██╗██╔══██╗╚══██╔══╝██║ ██║██╔══██╗██╔══██╗██╔════╝
# ██████╔╝██║ ██║ ██║███████║ ██║ ██║ █╗ ██║███████║██████╔╝█████╗
# ██╔══██╗██║ ██║ ██║██╔══██║ ██║ ██║███╗██║██╔══██║██╔══██╗██╔══╝
# ██████╔╝███████╗╚██████╔╝██║ ██║ ██║ ╚███╔███╔╝██║ ██║██║ ██║███████╗
# ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
#
# Remove HP bloatware / crapware
#
# -- source : https://gist.github.com/mark05e/a79221b4245962a477a49eb281d97388
# -- contrib: francishagyard2, mark05E, erottier, JoachimBerghmans, sikkepitje
# -- ref : https://community.spiceworks.com/topic/2296941-powershell-script-to-remove-windowsapps-folder?page=1#entry-9032247
# -- note : this script could use your improvements. contributions welcome!
# -- todo : Wolf Security improvements ref: https://www.reddit.com/r/SCCM/comments/nru942/hp_wolf_security_how_to_remove_it/
# -- improved by: loopyd <nightwintertooth@gmail.com> (loopyd@github.com)
#
# LICENSE - Unilicense
#
# 1. FREE, FOREVER
#
# This program is free software. It has been provided to you for free, at no charge, for your use
# or modification as you should so desire, but it should never be sold. As this software was created
# for the benefit of humanity as a whole, it goes agains that benefit to charge money for it. We
# ask that you do attempt to sell, or succeed in the sale or trade of in any monitory form, copies
# of this software modified, or unmodified, without permission from its authors.
#
#
# 2. USE THIS SOFTWARE AT YOUR OWN RISK
#
# The authors of this software assume no responsibility for damages it may cause to
# your computer, in its current or modified form. It has been tested to insure its stability on
# multiple machines. However, a case may arise that we or you in your modifications did not account
# for. Every effort has been made to mitigate the possibility of vital data loss. We however cannot
# gaurentee that this will work with every system configuration however.
#
# 3. PRIVACY CONSENT
#
# This software may create temporary files, however NO DATA is personally stored or shared on your
# system that should tie itself back to you as the user. Temporary files created by the script are
# destroyed, or may be left behind if the software uses a third party tool (such as a program's
# uninstaller) to remove them.
# This identifier is used to match HP software
$HPidentifier = "AD2F1837"
# List of built-in apps provided by HP, that we wish to target.
$Packages = @(
"HPJumpStarts"
"HPPCHardwareDiagnosticsWindows"
"HPPowerManager"
"HPPrivacySettings"
"HPSupportAssistant"
"HPSureShieldAI"
"HPSystemInformation"
"HPQuickDrop"
"HPWorkWell"
"myHP"
"HPDesktopSupportUtilities"
"HPQuickTouch"
"HPEasyClean"
"HPPCHardwareDiagnosticsWindows"
"HPProgrammableKey"
)
# List of programs provided by HP
$Programs = @(
"HP Client Security Manager"
"HP Connection Optimizer"
"HP Documentation"
"HP MAC Address Manager"
"HP Notifications"
"HP Security Update Service"
"HP System Default Settings"
"HP Sure Click"
"HP Sure Click Security Browser"
"HP Sure Run"
"HP Sure Recover"
"HP Sure Sense"
"HP Sure Sense Installer"
"HP Wolf Security"
"HP Wolf Security Application Support for Sure Sense"
"HP Wolf Security Application Support for Windows"
)
# A list of Windows Services to Disable (some are HP related, some not)
$Services = @(
"diagnosticshub.standardcollector.service"
"DiagTrack"
"dmwappushservice"
"lfsvc"
"MapsBroker"
"NetTcpPortSharing"
"RemoteAccess"
"RemoteRegistry"
"SharedAccess"
"TrkWks"
"WbioSrvc"
"WMPNetworkSvc"
"XblAuthManager"
"XblGameSave"
"XboxNetApiSvc"
"FxsSvc"
"ndu"
"AnalyticsClientService"
"AppHelperCap"
"DiagsCap"
"NetworkCap"
"SysInfoCap"
)
# A function that stops and disables a list of windows services.
function Disable-Services() {
param(
[Parameter(Position = 1, Mandatory = $true)][ref]$Services
)
Write-Host -ForegroundColor Cyan "ℹ️ Disabling $($Services.Value.Count) services..."
foreach ($Service in $Services.Value) {
$MyService = $Null
Try {
$MyService = Get-Service -Name $Service -ErrorAction Stop
} Catch {
Write-Host -ForegroundColor Yellow "♻️ Skipped service $($Service) as it is not installed!"
}
if ($MyService -ne $Null) {
Write-Host -ForegroundColor Yellow "🛑 Stopping service $($Service)..."
Try {
$MyService | Stop-Service -Force -ErrorAction Stop
Write-Host -ForegroundColor Green "✅ Stopped service $($Service)"
} Catch { Write-Warning -Message "❌ Failed to stop $($Service)" }
Write-Host -ForegroundColor Yellow "🛑 Disabling service $($Service)..."
Try {
$MyService | Set-Service -StartupType Disabled -Force -ErrorAction Stop
Write-Host -ForegroundColor Green "✅ Disabled service $($Service)"
} Catch { Write-Warning -Message "❌ Failed to disable $($Service)" }
}
}
return
}
## Function that is used to help return useful software information on the PC, it hecks for
# the matching software as an AppX/image provisioned package or legacy Programs and Features entry.
function Fetch-Software() {
param(
[Parameter(Position = 1, Mandatory = $True)][ref]$Packages,
[Parameter(Position = 2, Mandatory = $True)][ref]$Programs,
[Parameter(Position = 3, Mandatory = $True)][string]$PackageIdentifier,
[Parameter(Position = 4, Mandatory = $True)][string]$Manufacterer,
[Parameter(Mandatory = $False)][switch]$Simple = $False,
[Parameter(Mandatory = $False)][switch]$NoExit = $False
)
Write-Host -ForegroundColor Cyan "ℹ️ Scanning for $($Manufacterer) software..."
# Scan for AppX Packages using Get-AppxPackage, this checks for items in the current (online)
# Windows image. If we have not specified the -Simple flag, the packages matching our criteria
# are printed on output.
$InstalledPackages = Get-AppxPackage -AllUsers `
| Where-Object {( $("{0}.{1}" -f ($Packages.Value).Name, $PackageIdentifier) -contains $_.Name -or $_.Name -match $("^{0}" -f $PackageIdentifier))}
if ($InstalledPackages.Count -gt 0) {
Write-Host -ForegroundColor Yellow $("⚠️ Installed AppX packages found ({0}):" -f $InstalledPackages.Count)
if (-not $Simple) {
$InstalledPackages |% {
Write-Host -ForegroundColor Yellow $(" {0}" -f $_.Name )
}
}
} else {
Write-Host -ForegroundColor Green "✅ No $($Manufacterer) AppX packages."
}
# Scan for provisioned packages using Get-AppxProvisionedPackage, this checks for item in the
# base Windows image (allows changes to stick across "Reset this PC"). If we have not specified the
# -Simple flag, the provisioned packages matching our critera are printed on output.
$ProvisionedPackages = Get-AppxProvisionedPackage -Online `
| Where-Object {( $("{0}.{1}" -f ($Packages.Value).DisplayName, $PackageIdentifier) -contains $_.DisplayName -or $_.DisplayName -match $("^{0}" -f $PackageIdentifier))}
if ($ProvisionedPackages.Count -gt 0) {
Write-Host -ForegroundColor Yellow $("⚠️ Provisioned $($Manufacterer) packages found ({0}):" -f $InstalledPackages.Count)
if (-not $Simple) {
$ProvisionedPackages |% {
Write-Host -ForegroundColor Yellow $(" {0}" -f $_.DisplayName )
}
}
} else {
Write-Host -ForegroundColor Green "✅ No provisioned $($Manufacterer) packages."
}
# Scan for installed programs using Get-Package. This helps us uninstall programs that are not
# part of the Windows App registry (non-Microsoft Store) that match our criteria. If we have
# not specified the -Simple flag, the list of found programs is output.
$InstalledPrograms = Get-Package | Where-Object {( $("{0}.{1}" -f ($Programs.Value).Name, $PackageIdentifier) -contains $_.Name -or $_.Name -match $("^{0}" -f $PackageIdentifier))}
if ($InstalledPrograms.Count -gt 0) {
Write-Host -ForegroundColor Yellow $("⚠️ Installed $($Manufacterer) Programs found ({0}):" -f $InstalledPrograms.Count)
if (-not $Simple) {
$InstalledPrograms |% {
Write-Host -ForegroundColor Yellow $(" {0}" -f $_.Name )
}
}
} else {
Write-Host -ForegroundColor Green "✅ No remaining HP programs."
}
# Display a message and exit the script if we have specfied that we would like to exit via omitting
# the -NoExit flag to the function call.
if (-not $NoExit -and $InstalledPackages.Count -eq 0 -and $ProvisionedPackages.Count -eq 0 -and $InstalledPrograms.Count -eq 0) {
Write-Host -ForegroundColor Green "✅ No HP software found, the script will now exit."
Exit 1
}
# Construct results into a PSCustom object that makes them easy to reference and return the object
$HPSoftware = New-Object -TypeName PSCustomObject -Property @{ `
"InstalledPackages" = $InstalledPackages
"ProvisionedPackages" = $ProvisionedPackages
"InstalledPrograms" = $InstalledPrograms
}
return $HPSoftware
}
function Prompt-Reboot() {
# Feature - Ask for reboot after running the script
Write-Host -NoNewline -ForegroundColor Cyan "Restart computer now? [y/n] "
$input = Read-Host
switch($input) {
y{Restart-computer -Force -Confirm:$false}
n{return}
default{write-warning "Skipping reboot."}
}
return
}
# Block the script from not being run as an Administrator -- Improvement / sanity check
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Warning -Message "❌ Not running as administrator! Please re-run your terminal session as Administrator, and try again."
}
# Fetch the software
$HPSoftware = Fetch-Software -Packages ([ref]$Packages) -Programs ([ref]$Programs) -PackageIdentifier $HPidentifier -Manufacterer "HP" -Simple -NoExit
Write-Host -ForegroundColor Cyan "ℹ️ Found $($HPSoftware.InstalledPackages.Count) installed, $($HPSoftware.ProvisionedPackages.Count) provisioned, and $($HPSoftware.InstalledPrograms.Count) HP programs."
# Remove appx provisioned packages - AppxProvisionedPackage
ForEach ($ProvPackage in $HPSoftware.ProvisionedPackages) {
Write-Host -ForegroundColor Yellow "💣 Attempting to remove provisioned package: [$($ProvPackage.DisplayName)]..."
Try {
$Null = Remove-AppxProvisionedPackage -PackageName $ProvPackage.PackageName -Online -ErrorAction Stop
Write-Host -Object -ForegroundColor Green "Successfully removed provisioned package: [$($ProvPackage.DisplayName)]"
}
Catch {Write-Warning -Message "❌ Failed to remove provisioned package: [$($ProvPackage.DisplayName)]"}
}
# Remove AppX packages - AppxPackage
ForEach ($AppxPackage in $HPSoftware.InstalledPackages) {
Write-Host -ForegroundColor Yellow "💣 Attempting to remove AppX package: [$($AppxPackage.Name)]..."
Try {
$Null = Remove-AppxPackage -Package $AppxPackage.PackageFullName -AllUsers -ErrorAction Stop
Write-Host -ForegroundColor Green "✅ Successfully removed AppX package: [$($AppxPackage.Name)]"
}
Catch {Write-Warning -Message "❌ Failed to remove AppX package: [$($AppxPackage.Name)]"}
}
# Remove installed programs
ForEach ($Program in $HPSoftware.InstalledPrograms) {
Write-Host -ForegroundColor Yellow "💣 Attempting to uninstall: [$($Program.Name)]..."
Try {
$Null = $Program | Uninstall-Package -AllVersions -Force -ErrorAction Stop
Write-Host -ForegroundColor Green "✅ Successfully uninstalled: [$($Program.Name)]"
}
Catch {Write-Warning -Message "❌ Failed to uninstall: [$($Program.Name)]"}
}
# Fallback attempt 1 to remove HP Wolf Security using msiexec
Try {
MsiExec /x "{0E2E04B0-9EDD-11EB-B38C-10604B96B11E}" /qn /norestart
Write-Host -ForegroundColor Yellow "⚠️ Fallback to MSI uninistall for HP Wolf Security initiated"
}
Catch {
Write-Warning -Message "❌ Failed to uninstall HP Wolf Security using MSI - Error message: $($_.Exception.Message)"
}
# Fallback attempt 2 to remove HP Wolf Security using msiexec
Try {
MsiExec /x "{4DA839F0-72CF-11EC-B247-3863BB3CB5A8}" /qn /norestart
Write-Host -ForegroundColor Yellow "⚠️ Fallback to MSI uninistall for HP Wolf 2 Security initiated"
}
Catch {
Write-Warning -Message "❌ Failed to uninstall HP Wolf Security 2 using MSI - Error message: $($_.Exception.Message)"
}
$HPSoftware = Fetch-Software -Packages ([ref]$Packages) -Programs ([ref]$Programs) -PackageIdentifier $HPidentifier -Manufacterer "HP" -Simple -NoExit
Disable-Services -Services ([ref]$Services)
Write-Host -ForegroundColor Blue "✨ HP Debloat complete!"
Prompt-Reboot
@sstalon
Copy link

sstalon commented Sep 28, 2023

How would I do this in a Intune Remediation? Any ideas?

@superswan
Copy link

Does too much, I want to remove HP's bloatware not disable a bunch of services. Also gets caught on stopping Windows Network Data Usage Monitoring Driver on every device I've tried this version on. Thumbs up for UI improvements though.

@loopyd
Copy link
Author

loopyd commented Nov 13, 2023

Does too much, I want to remove HP's bloatware not disable a bunch of services. Also gets caught on stopping Windows Network Data Usage Monitoring Driver on every device I've tried this version on. Thumbs up for UI improvements though.

Tell me more about "caught up". Does it freeze/hang or cause an error? If you see this happening consistently, give me the name of the service and I'll consider removing it from the default list. This is made to be customizable.

I am also happy to implement parameter switches to enable/disable select functionality, read config on which programs, services, appx, and provisioned packages to remove from a json config file, and further modularize, but I will need some more information from you about this issue.

@loopyd
Copy link
Author

loopyd commented Nov 13, 2023

How would I do this in a Intune Remediation? Any ideas?

  • This would require downgrading some of the script's features to PowerShell 2.0. Intune Remediation is not compatible with PowerShell 7. Though this is possible to do would need some additional research / testing to perform an auto-elevation to pwsh.exe without creating a subprocess and copying in the $PSProfile and environment (this would cause problems in InTune Remediation).

Blah blah: I do have an auto installer/auto escalator/runner under "Preflight checks" for PowerShell 7that forks a PS2.0 Administrator process into PowerShell 7 via embedded iex without jumping ship on the current process after installing it as an MSI package... in my gists (see blep api's auto PS7 elevator), and then reading back the registry keys to find out where it is, but this would add an extra package to the system just to run the script in Intune as PowerShell 7.0 without causing a subproccess fork that would make the remediation throw a deployment error, whether or not the user is okay with that? I feel that doing so may be out of scope. It is also a lot of messy polyglot code I don't recommend you use in production...

@superswan
Copy link

superswan commented Nov 13, 2023

Does too much, I want to remove HP's bloatware not disable a bunch of services. Also gets caught on stopping Windows Network Data Usage Monitoring Driver on every device I've tried this version on. Thumbs up for UI improvements though.

Tell me more about "caught up". Does it freeze/hang or cause an error? If you see this happening consistently, give me the name of the service and I'll consider removing it from the default list. This is made to be customizable.

I am also happy to implement parameter switches to enable/disable select functionality, read config on which programs, services, appx, and provisioned packages to remove from a json config file, and further modularize, but I will need some more information from you about this issue.

Yes, configurable options would be helpful. It endlessly loops on "stopping Windows Network Data Usage Monitoring Driver" without failing, preventing the script from continuing, I'll have some new HP laptops to test it on again soon.

As opposed to a config file maybe just a parameter switch as you suggested would be a great place to start -services-win ,-services-hp, -all, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment