-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHideWinUpdates.ps1
More file actions
91 lines (76 loc) · 3.13 KB
/
Copy pathHideWinUpdates.ps1
File metadata and controls
91 lines (76 loc) · 3.13 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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<#Carlos Martinez Date: 11/10/2019 GitHub @cmartinezone
DESCRIPTION: Set Windows 10 Updates as hidden.
The script hides the Windows updates from windows updates list.
EXAMPLE:
Get list of updates IDs : .\HideWinUpdates.ps1 -Action GetUpdateList
Hide Single Update : .\HideWinUpdates.ps1 -Action HideUpdate -IDs "XXXXXXX"
Hide Multiple Updates : .\HideWinUpdates.ps1 -Action HideUpdate -IDs ("XXXXXXX","XXXXXXX")
#>
Param(
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeLine = $false)]
[ValidateSet("GetUpdateList", "HideUpdate")]
$Action,
[Parameter(Mandatory = $false, Position = 1, ValueFromPipeLine = $false)]
[Object[]]$IDs
)
#Create object session for windows updates
$session = new-object -ComObject Microsoft.Update.Session
#Windows Object searcher
$searcher = $session.CreateUpdateSearcher()
#Get List of updates not installed
$result = $searcher.Search("IsInstalled=0")
#Function to print the list of updates availble
function GetUpdateIDs {
$result.Updates | ForEach-Object {
Write-Host
Write-Host "Title : " -ForegroundColor Yellow -NoNewline ; Write-Host $_.Title
Write-Host "KBArticleIDs: " -ForegroundColor Yellow -NoNewline ; Write-Host $_.KBArticleIDs
Write-Host "IsHidden : " -ForegroundColor Yellow -NoNewline ; Write-Host $_.IsHidden
}
if ( $null -eq $result.Updates ) {
Write-Host "No updates availble" -ForegroundColor Yellow
}
}
#Function to Hide Updates.
function HideUpdates {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[Object[]]$UpdateIDs
)
#Get Update List
$Updatelist = $result.Updates
$LastUpdateStatus = @() #empty object to store the last status of the updates.
$Updatelist | ForEach-Object {
#If the Update exists on the object array of updates and it is already hidden.
if ( $_.KBArticleIDs -in $UpdateIDs -and $true -eq $_.IsHidden ) {
Write-Host
Write-Host "The Update is already hidden: " -ForegroundColor Yellow -NoNewline
Write-Host $_.KBArticleIDs -ForegroundColor Green
$LastUpdateStatus += $_ #store update status.
}
#If the update is exists on the object array of updates and it is not hidden.
if ( $_.KBArticleIDs -in $UpdateIDs -and $false -eq $_.IsHidden ) {
try {
#Set Update as Hidden.
$_.IsHidden = $true
Write-Host
Write-Host "The Update has been successfully hidden: " -ForegroundColor Yellow -NoNewline
Write-Host $_.KBArticleIDs -ForegroundColor Green
$LastUpdateStatus += $_ #store update status.
}
catch {
$error = $_.Exception.Message
Write-Host "FAILED:"$error -ForegroundColor Red
}
}
}
#Print Object of update status.
$LastUpdateStatus | Select-Object Title, IsHidden
}
if ($Action -eq "GetUpdateList" -and $null -eq $IDs ) {
GetUpdateIDs
}
if ($Action -eq "HideUpdate" -and $null -ne $IDs) {
HideUpdates -UpdateIDs $IDs
}