forked from zmottie/Get-WindowsHotfixes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHyperV2012UpdatesCheck.ps1
151 lines (130 loc) · 5.01 KB
/
HyperV2012UpdatesCheck.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Remake of Christian Edwards script to make it more flexible
# http://blogs.technet.com/b/cedward/archive/2013/05/31/validating-hyper-v-2012-and-failover-clustering-hotfixes-with-powershell-part-2.aspx
#
# Niklas Akerlund 2013-06-28
<#
.SYNOPSIS
Powershell script intended for checking Windows Server hosts for hotfixes and updates published for Hyper-V and Failover Cluster rule in Windows Server 2012.
.DESCRIPTION
Script use xml files UpdatesListCluster.xml and UpdatesListHyperV.xml that are stored in folder with script.
.PARAMETER ComputerName
The name of the Computer you want to run the command against.
.PARAMETER ClusterName
Optional - The Cluster which contains the nodes you'd like to run the report against.
.PARAMETER Download
Optional - Download all hotfixes which are not currently installed.
.PARAMETER DownloadPath
Optional - Download path. Must be entered when -Download is used.
.EXAMPLE
.\HyperV2012UpdatesCheck.ps1 -ClusterName mycluster -Download -DownloadPath c:\temp\hotfixes
.LINK
https://github.com/it-praktyk/Get-WindowsHotfixes
#>
param
(
[parameter(ValueFromPipeline=$true,
Position=0)]
[string]$Hostname,
[parameter(ValueFromPipeline=$true,
Position=1)]
$ClusterName,
[switch]$Download,
[string]$DownloadPath
)
#Getting current execution path
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
$listofHotfixes = @()
#Loading list of updates from XML files
[xml]$SourceFileHyperV = Get-Content $dir\UpdatesListHyperV.xml
[xml]$SourceFileCluster = Get-Content $dir\UpdatesListCluster.xml
$HyperVHotfixes = $SourceFileHyperV.Updates.Update
$ClusterHotfixes = $SourceFileCluster.Updates.update
#Getting installed Hotfixes from all nodes of the Cluster
if ($ClusterName){
$Nodes = Get-Cluster $ClusterName | Get-ClusterNode | Select -ExpandProperty Name
}else
{
$Nodes = $Hostname
}
foreach($Node in $Nodes)
{
$Hotfixes = Get-HotFix -ComputerName $Node |select HotfixID,description
foreach($RecomendedHotfix in $HyperVHotfixes)
{
$witness = 0
foreach($hotfix in $Hotfixes)
{
If($RecomendedHotfix.id -eq $hotfix.HotfixID)
{
$obj = [PSCustomObject]@{
HyperVNode = $Node
HotfixType = "Hyper-V"
RecomendedHotfix = $RecomendedHotfix.Id
Status = "Installed"
Description = $RecomendedHotfix.Description
DownloadURL = $RecomendedHotfix.DownloadURL
}
$listOfHotfixes += $obj
$witness = 1
}
}
if($witness -eq 0)
{
$obj = [PSCustomObject]@{
HyperVNode = $Node
HotfixType = "Hyper-V"
RecomendedHotfix = $RecomendedHotfix.Id
Status = "Not Installed"
Description = $RecomendedHotfix.Description
DownloadURL = $RecomendedHotfix.DownloadURL
}
$listofHotfixes += $obj
}
}
foreach($RecomendedClusterHotfix in $ClusterHotfixes)
{
$witness = 0
foreach($hotfix in $Hotfixes)
{
If($RecomendedClusterHotfix.id -eq $hotfix.HotfixID)
{
$obj = [PSCustomObject]@{
HyperVNode = $Node
HotfixType = "Cluster"
RecomendedHotfix = $RecomendedClusterHotfix.Id
Status = "Installed"
Description = $RecomendedClusterHotfix.Description
DownloadURL = $RecomendedClusterHotfix.DownloadURL
}
$listOfHotfixes += $obj
$witness = 1
}
}
if($witness -eq 0)
{
$obj = [PSCustomObject]@{
HyperVNode = $Node
HotfixType = "Cluster"
RecomendedHotfix = $RecomendedClusterHotfix.Id
Status = "Not Installed"
Description = $RecomendedClusterHotfix.Description
DownloadURL = $RecomendedClusterHotfix.DownloadURL
}
$listOfHotfixes += $obj
}
}
}
if ($Download){
foreach($RecomendedHotfix in $HyperVHotfixes){
if ($RecomendedHotfix.DownloadURL -ne ""){
Start-BitsTransfer -Source $RecomendedHotfix.DownloadURL -Destination $DownloadPath
}
}
foreach($RecomendedClusterHotfix in $ClusterHotfixes){
if ($RecomendedClusterHotfix.DownloadURL -ne ""){
Start-BitsTransfer -Source $RecomendedClusterHotfix.DownloadURL -Destination $DownloadPath
}
}
}
$listofHotfixes