-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reset-WsusDrivers.ps1
66 lines (60 loc) · 2.79 KB
/
Reset-WsusDrivers.ps1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# The original version of this script is authored by Liby Philip Mathew and was obtained through this link:
# https://libyphilip.wordpress.com/2017/01/04/how-to-delete-driver-updates-from-wsus/
# Requires RSAT for WSUS
# Windows Server: Add-WindowsFeature -Name UpdateServices-RSAT -IncludeAllSubFeature;
# Windows Desktop: Add-WindowsCapability -Online -Name Rsat.WSUS.Tools~~~~0.0.1.0;
param(
[string] $WsusServer = ([System.Net.Dns]::GetHostByName('localhost')).HostName,
[int] $PortNumber = 8530,
[bool] $UseSSL = $false
)
# Changing the default action on error, warning, and progress
$EPref = $ErrorActionPreference;
$WPref = $WarningPreference;
$PPref = $ProgressPreference;
$ErrorActionPreference = 'Stop';
$WarningPreference = 'SilentlyContinue';
$ProgressPreference = 'SilentlyContinue';
Write-Host "Disabling and removing WSUS drivers..."
try {
[Reflection.Assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null;
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($WsusServer, $UseSSL, $PortNumber);
Get-WsusClassification -UpdateServer $wsus | Where-Object -FilterScript {$_.Classification.Title -eq "Drivers"} | Set-WsusClassification -Disable;
Get-WsusClassification -UpdateServer $wsus | Where-Object -FilterScript {$_.Classification.Title -eq "Driver Sets"} | Set-WsusClassification -Disable;
$Updates = $wsus.GetUpdates();
$Drivers = $Updates | Where-Object {($_.UpdateClassificationTitle -eq 'Drivers') -or ($_.UpdateClassificationTitle -eq 'Driver Sets')}
Write-Host "-> [$($Updates.Count) updates and $($Drivers.Count) drivers found]"
$Count = 0;
$Update = "";
$Drivers | ForEach-Object {
$Count += 1;
$Update = $_.Title;
try {
$wsus.DeleteUpdate($_.Id.UpdateID);
Write-Host "$Count/$($Drivers.Count): '$Update' removed successfully!" -ForegroundColor Green;
} catch {
Write-Host "$Count/$($Drivers.Count): '$Update' removal failed!" -ForegroundColor Red;
}
}
} catch {
Write-Host "Failed to find, connect and/or take action in WSUS!" -ForegroundColor Red;
Write-Host "Is RSAT for WSUS installed? Are you using credentials with sufficient privileges?" -ForegroundColor Yellow;
Write-Host $_.Exception.GetType().FullName;
Write-Host $_.Exception.Message;
}
Write-Host "-------------------------------> Done.";
# Restoring the default action on error, warning and progress
$ErrorActionPreference = $EPref;
$WarningPreference = $WPref;
$ProgressPreference = $PPref;
# Cleaning up
Clear-Variable Count;
Clear-Variable Drivers;
Clear-Variable EPref;
Clear-Variable PortNumber;
Clear-Variable PPref;
Clear-Variable Update;
Clear-Variable Updates;
Clear-Variable WPref;
Clear-Variable wsus;
Clear-Variable WsusServer;