Skip to content

Instantly share code, notes, and snippets.

@WinkelCode
Last active January 2, 2023 19:19
Show Gist options
  • Save WinkelCode/cae44ddce205b5363c60f15b2748ad1e to your computer and use it in GitHub Desktop.
Save WinkelCode/cae44ddce205b5363c60f15b2748ad1e to your computer and use it in GitHub Desktop.
Use at your own risk
# Script to automatically remove "appleprecisiontrackpadbluetooth.inf" and "appleprecisiontrackpadusb.inf".
# Get installed drivers with pnputil and include previous line (the published name)
$drivers = (pnputil /enum-drivers | Select-String -Pattern "appleprecisiontrackpadbluetooth.inf|appleprecisiontrackpadusb.inf" -Context 1,0)
# Sanity check the results
switch ($drivers.Count) {
0 {Write-Host "No drivers found, exiting"; pause; exit}
1 {Write-Host "Only one driver found, are you sure you want to continue?"; Read-Host "Press any key to continue, or Ctrl+C to abort"; Write-Host "Continuing"}
2 {Write-Host "Two drivers found, continuing"}
default {Write-Host "More than two drivers found, something seems to be broken. Please check manually with 'pnputil /enum-drivers'"; pause; exit}
}
# For each found driver...
foreach ($driver in $drivers) {
# Get the "Published Name" for pnputil /delete-driver (doesn't work with "Original Name").
$driverpubname = $driver.Context.PreContext -split " " | Select-Object -Last 1
# The "original name" for info purposes.
$driverorigname = $driver.Line -split " " | Select-Object -Last 1
Write-Host "Will remove $driverorigname ($driverpubname)"
Read-Host "Continue? (Note: If you aren't sure, check manually with 'pnputil /enum-drivers') - Press any key to continue, or Ctrl+C to abort"
# Without /force it won't work in most cases without other steps, shouldn't cause any issues here.
pnputil /delete-driver $driverpubname /force
}
Write-Host "Done"
pause
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment