forked from farag2/Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelete_old_drivers.ps1
More file actions
26 lines (22 loc) · 1.27 KB
/
Delete_old_drivers.ps1
File metadata and controls
26 lines (22 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$OriginalFileName = @{
Name = "OriginalFileName"
Expression = {$_.OriginalFileName | Split-Path -Leaf}
}
$Date = @{
Name = "Date"
Expression = {$_.Date.Tostring().Split("")[0]}
}
$AllDrivers = Get-WindowsDriver -Online -All | Where-Object -FilterScript {$_.Driver -like 'oem*inf'} | Select-Object -Property $OriginalFileName, Driver, ClassDescription, ProviderName, $Date, Version
Write-Verbose -Message "All installed third-party drivers" -Verbose
($AllDrivers | Sort-Object -Property ClassDescription | Format-Table -AutoSize -Wrap | Out-String).Trim()
$DriverGroups = $AllDrivers | Group-Object -Property OriginalFileName | Where-Object -FilterScript {$_.Count -gt 1}
Write-Verbose -Message "Duplicate drivers" -Verbose
($DriverGroups | ForEach-Object -Process {$_.Group | Sort-Object -Property Date -Descending | Select-Object -Skip 1} | Format-Table | Out-String).Trim()
$DriversToRemove = $DriverGroups | ForEach-Object -Process {$_.Group | Sort-Object -Property Date -Descending | Select-Object -Skip 1}
Write-Verbose -Message "Drivers to remove" -Verbose
($DriversToRemove | Sort-Object -Property ClassDescription | Format-Table | Out-String).Trim()
foreach ($item in $DriversToRemove)
{
$Name = $($item.Driver).Trim()
& pnputil.exe /delete-driver "$Name" /force
}