Skip to content

Instantly share code, notes, and snippets.

@JonathonAnderson
Last active September 4, 2019 15:47
Show Gist options
  • Save JonathonAnderson/98edcb9bd0307a4d111806c19f835961 to your computer and use it in GitHub Desktop.
Save JonathonAnderson/98edcb9bd0307a4d111806c19f835961 to your computer and use it in GitHub Desktop.
Remove-DeviceDriver
$InstalledDrivers = $(pnputil.exe /enum-drivers)
$DriversToDelete = @( "netwtw04.inf"; "netwtw06.inf"; "netwtw08.inf" )
$OemInfs = New-Object -TypeName System.Collections.ArrayList -ArgumentList $DriversToDelete.Count
for($i = 0; $i -lt $InstalledDrivers.Length ; $i++ )
{
foreach($Driver in $DriversToDelete)
{
if($InstalledDrivers[$i] -like "*$Driver")
{
$null = $OemInfs.Add( ($InstalledDrivers[$i-1] -split ":")[1] -replace " " )
}
}
}
$UninstallExe = "$env:windir\System32\pnputil.exe"
foreach($Inf in $OemInfs)
{
$UninstallArgs = "/delete-driver $Inf /uninstall /force"
$UninstallSplat = @{ Path = $UninstallExe; Parameters = $UninstallArgs; NoWait = $false }
$UninstallReturn = Execute-Process @UninstallSplat
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment