Advertisement
aveyo

Uninstall OEM Drivers - PNPUTIL frontend

Oct 12th, 2018
2,428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.39 KB | None | 0 0
  1. <# ::  PNPUTIL frontend by AveYo
  2. @title Uninstall OEM Drivers
  3. @start "" powershell.exe -noprofile -c "Invoke-Expression ('& {' + [io.file]::ReadAllText(\"%~f0\") + '}')" & exit/b
  4. :: can also copy-paste directly into a powershell window #>
  5.  
  6. reg query "HKEY_USERS\S-1-5-20" 2>&1 | out-null; $admin = ($LASTEXITCODE -eq 0)
  7. $title='To uninstall OEM drivers, right-click script and Run as Administrator!'
  8. if ($admin) {$title='WARNING! selected OEM drivers will be uninstalled, press ESC to cancel'}
  9. $skip = $true
  10. $header = $true
  11. $oem = New-Object System.Collections.ArrayList
  12. $drivers = (pnputil.exe /enum-drivers) -join "`v" -split "`v`v";
  13. foreach($item in $drivers){
  14.   if ($skip) { $skip = $false; continue }
  15.   $obj =  New-Object -TypeName PSObject
  16.   $props = $item -split "`v"
  17.   foreach($p in $props){
  18.     $entry = $p -split ":\s+",2
  19.     if ($entry[0] -ne ''){ $obj | Add-Member -MemberType NoteProperty -Name ($entry[0]) -Value ($entry[1]) -Force}
  20.   }
  21.   if ($header){
  22.     $dummy = New-Object PsObject # safeguard for the first entry being selected by default
  23.     $obj.psobject.properties | foreach { $dummy | Add-Member -MemberType $_.MemberType -Name $_.Name -Value ' ' }
  24.     $null = $oem.Add($dummy)
  25.     $header = $false
  26.   }
  27.   $null = $oem.Add($obj)
  28. }
  29. $oem | Out-GridView -Title $title -PassThru | foreach{$i=$_.('Published Name');pnputil.exe /delete-driver $i /force;echo "$i`n"}
  30. timeout /t -1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement