-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestHideUnhideWU.ps1
More file actions
67 lines (58 loc) · 1.97 KB
/
TestHideUnhideWU.ps1
File metadata and controls
67 lines (58 loc) · 1.97 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
<#
.Synopsis
Used as When to Call Install Complete custom script for HideUnhideWU.ps1
.NOTES
Created: October, 2021
Created by: Phil Helmling, @philhelmling
Organization: VMware, Inc.
Filename: TestHideUnhideWU.ps1
GitHub: https://github.com/helmlingp/apps_WindowsUpdates
.DESCRIPTION
Used to test if a KB is hidden or not. Used in conjunction with HideUnhideWU.ps1 in same repo for "When to Call Install Complete" logic.
*** Hide KB
When to Call Install Complete:
Identify Application By: Using Custom Script
Script Type: Powershell
Command to run script: powershell.exe -ep bypass -file .\TestHideUnhideWU.ps1 -HideKBs KBARTICLEID
Success Exit Code: 0
**** IMPORTANT ****
-HideKBs KBARTICLEID parameter must match the Install Command -HideKBs KBARTICLEID parameter
#>
param (
[Parameter(ValueFromRemainingArguments=$true)]
[string[]]$HideKBs=$script:HideKBs,
[Parameter(ValueFromRemainingArguments=$true)]
[string[]]$UnhideKBs=$script:UnhideKBs
)
Try { Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force -ErrorAction Stop } Catch {}
$ec = 1
$PackageProvider = Get-PackageProvider -ListAvailable
$NuGetInstalled = $false
foreach ($item in $PackageProvider.name){
if($item -eq "NuGet")
{
$NuGetInstalled = $true
}
}
if($NuGetInstalled = $false){
Install-PackageProvider NuGet -Force
}else{
Get-PackageProvider -Name NuGet -Force
Write-Output "NuGet is already installed"
}
$ModuleInstalled = Get-Module PSWindowsUpdate
if(!$ModuleInstalled){
Install-Module -Name PSWindowsUpdate -Force
}else{
Write-Output "PSWindowsUpdate Module is already installed"
}
Import-Module -Name "PSwindowsUpdate" -MinimumVersion 2.2.0.2
if($HideKBs){$KB = $HideKBs}
if($UnhideKBs){$KB = $UnhideKBs}
$ishidden = Get-WindowsUpdate -IsHidden
foreach ($hiddenkb in $ishidden.KB) {
if ($hiddenkb -eq $KB) {
$ec = 0
}
}
exit $ec