-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpgrade-IMMServerFirmware.ps1
More file actions
358 lines (296 loc) · 13.3 KB
/
Upgrade-IMMServerFirmware.ps1
File metadata and controls
358 lines (296 loc) · 13.3 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#requires -version 3.0
#requires -Modules 'IMM-Module'
<#
.SYNOPSIS
Upgrade IBM server's Firmware.
Make use of "IMM-Module.psm1" PowerShell module and BoMC unattended ISO image.
.DESCRIPTION
This script upgrade IBM server's Firmware from BoMC ISO image.
Make use of "IMM-Module.psm1" PowerShell module and BoMC unattended ISO image.
.PARAMETER IMM
IMM DNS name or IP address.
.PARAMETER IMMCred
IMM Supervisor Credentials (optional, default Get-Credential Cmdlet object).
.PARAMETER IMMLog
Firmware upgrade process log file (optional, change default value to meet your environment).
.PARAMETER IMMConfig
Generic IMM config CSV-file (optional, change default value to meet your environment).
.PARAMETER BoMC
BoMC prepared unattended Firmware ISO file (optional, change default value to meet your environment).
.EXAMPLE
.\Upgrade-IMMServerFirmware.ps1 '10.98.1.150'
.EXAMPLE
$immCred = Get-Credential -UserName yourlogin -Message "IMM credentials"
.\Upgrade-IMMServerFirmware.ps1 -IMM '10.98.1.150' -IMMCred $immCred `
-Log 'C:\reports\fwUpgrade.log' -Config 'C:\reports\immSettings.csv' -ISO 'C:\BoMC_x3690X5.iso'
.NOTES
Author: Roman Gelman
.LINK
http://goo.gl/VCjjFI
#>
#region Params
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="IMM DNS name or IP address")]
[ValidateNotNullorEmpty()]
[System.String]$IMM
,
[Parameter(Mandatory=$false,Position=1,HelpMessage="IMM Supervisor Credentials")]
[ValidateNotNullorEmpty()]
[Alias("Credentials")]
[System.Management.Automation.PSCredential]$IMMCred = (Get-Credential -UserName ribadmin -Message "IMM Supervisor Login")
,
[Parameter(Mandatory=$false,Position=2,HelpMessage='Firmware upgrade process log file (txt|log)')]
[ValidatePattern('(txt$|log$)')]
[ValidateScript({Test-Path -Path (Split-Path -Path $_) -PathType Container})]
[Alias("Log")]
[System.String]$IMMLog = "E:\sh\IBM\immUpgrade.log"
,
[Parameter(Mandatory=$false,Position=3,HelpMessage='Generic IMM config file (csv)')]
[ValidatePattern('csv$')]
[ValidateScript({Test-Path -Path FileSystem::$_ -PathType Leaf})]
[Alias("Config")]
[System.String]$IMMConfig = "E:\sh\IBM\immSettings.csv"
,
[Parameter(Mandatory=$false,Position=4,HelpMessage='BoMC prepared unattended Firmware ISO file')]
[ValidatePattern('iso$')]
[ValidateScript({Test-Path -Path FileSystem::$_ -PathType Leaf})]
[Alias("ISO")]
[System.String]$BoMC = '\\NTMAHR16\srvinst$\IBM\BoMC_9.63_TFTP.iso'
)
#endregion Params
#region Functions
Function Get-CurrentTime {
Get-Date -Format "[HH:mm:ss]"
}
#endregion Functions
#region Prefly
If (Test-Path -Path $IMMLog) {clc -Path $IMMLog -Confirm:$false}
If (!(Test-Path -Path FileSystem::$BoMC -PathType Leaf)) {Exit 1}
$Host.UI.RawUI.WindowTitle = "Upgrade Firmware - '$IMM'"
If ($IMMCred) {
$IMMLogin = $IMMCred.GetNetworkCredential().UserName
$IMMPwd = $IMMCred.GetNetworkCredential().Password
}
#endregion Prefly
#region Get IMM Info
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tGathering IMM Info ..." -ForegroundColor Yellow
$immDummy = $null
$immDummy = Get-IMMInfo -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd
If ($immDummy.Serial -ne '') {
$immDummy |ft -AutoSize
"$tsTime`tIMM Info" >> $IMMLog
$immDummy |fl >> $IMMLog
} Else {
$immDummy = $null
$immDummy = Get-IMMInfo -IMM $IMM
If ($immDummy.Serial -ne '') {
$immDummy |ft -AutoSize
"$tsTime`tIMM Info" >> $IMMLog
$immDummy |fl >> $IMMLog
} Else {
Write-Host "$tsTime`tFailed to communicate with IMM`n" -ForegroundColor Red
Exit 1
}
}
#endregion Get IMM Info
#region Create Supervisor Login Profile (if not exists yet)
If ($IMMLogin -ne 'USERID') {
$login2Name = (Get-IMMParam -IMM $IMM -Param 'LoginId.2').Value
$login1Level = (Get-IMMParam -IMM $IMM -Param 'AuthorityLevel.1').Value
If ($login2Name -ne $IMMLogin -and $login1Level -eq 'Supervisor' ) {
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tCreate Supervisor Login Profile ..." -ForegroundColor Yellow
"$tsTime`tCreate Supervisor Login Profile" >> $IMMLog
$immLoginId = @()
$immLoginId += Set-IMMParam -IMM $IMM -Confirm:$false -Param 'LoginId.2' -Value $IMMLogin
$immLoginId += Set-IMMParam -IMM $IMM -Confirm:$false -Param 'Password.2' -Value $IMMPwd
$immLoginId += Set-IMMParam -IMM $IMM -Confirm:$false -Param 'AuthorityLevel.2' -Value Supervisor
$immLoginId += Set-IMMParam -IMM $IMM -Confirm:$false -Param 'AuthorityLevel.1' -Value ReadOnly -IMMLogin $IMMLogin -IMMPwd $IMMPwd
$immLoginId |ft -AutoSize
$immLoginId |fl >> $IMMLog
}
} Else {
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tCustom Supervisor Login Profile already exists ..." -ForegroundColor Yellow
"$tsTime`tCustom Supervisor Login Profile already exists" >> $IMMLog
$IMMLogin = 'USERID'
$IMMPwd = 'PASSW0RD'
}
#endregion Create Supervisor Login Profile
#region Save and Change BootOrder ("CD/DVD Rom" first)
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tSave and Change Boot Order ..." -ForegroundColor Yellow
$origBO = Get-IMMServerBootOrder -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd
$origBO |ft -AutoSize
"$tsTime`tOriginal Boot Order" >> $IMMLog
$origBO |fl >> $IMMLog
If ($origBO.Boot1 -ne 'CD/DVD Rom') {
$needChangeBO = $true
$cdBO = Set-IMMServerBootOrder -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd -Confirm:$false
$tsTime = Get-CurrentTime
If ($cdBO.Boot1 -ne '') {
Write-Host "$tsTime`tBoot Order successfully changed" -ForegroundColor Green
"$tsTime`tBoot Order successfully changed" >> $IMMLog
} Else {
Write-Host "$tsTime`tFailed to change Boot Order`n" -ForegroundColor Red
"$tsTime`tFailed to change Boot Order" >> $IMMLog
Exit 1
}
} Else {
$needChangeBO = $false
Write-Host "$tsTime`tNo need to change Boot Order" -ForegroundColor Green
"$tsTime`tNo need to change Boot Order" >> $IMMLog
}
#endregion Save and Change BootOrder ("CD/DVD Rom" first)
#region Set Generic Enterprise settings from config file
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tSet Generic Enterprise IMM parameters from config file '$IMMConfig' ..." -ForegroundColor Yellow
"$tsTime`tSet Generic Enterprise IMM parameters from config file '$IMMConfig'" >> $IMMLog
$i = 0
Import-Csv $IMMConfig |% {
$key = $_.IMMKey
$value = $_.IMMValue
$i += 1
$immDummy = $null
$immDummy = Set-IMMParam -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd -Param $key -Value $value -Confirm:$false
If ($immDummy.Value -ne '') {Write-Host "`t[$i] $($immDummy.Param) = $($immDummy.Value)" -ForegroundColor Green}
Else {Write-Host "`t[$i] $($immDummy.Param) = $($immDummy.Value)" -ForegroundColor Red}
"`t[$i] '$($immDummy.Param)' = '$($immDummy.Value)'" >> $IMMLog
}
#endregion Set Generic Enterprise settings from config file
#region Set IMM Name
If ($IMM -match "^[a-zA-Z]+.*") {
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tSet IMM Name ..." -ForegroundColor Yellow
"$tsTime`tSet IMM Name" >> $IMMLog
$immDummy = $null
$immDummy = Set-IMMParam -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd -Param 'IMMInfo_Name' -Value $IMM -Confirm:$false
If ($immDummy.Value -ne '') {Write-Host "`t[1] $($immDummy.Param) = $($immDummy.Value)" -ForegroundColor Green}
Else {Write-Host "`t[1] $($immDummy.Param) = $($immDummy.Value)" -ForegroundColor Red}
"`t[1] '$($immDummy.Param)' = '$($immDummy.Value)'" >> $IMMLog
$immDummy = $null
$immDummy = Set-IMMParam -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd -Param 'HostName1' -Value $IMM -Confirm:$false
If ($immDummy.Value -ne '') {Write-Host "`t[2] $($immDummy.Param) = $($immDummy.Value)" -ForegroundColor Green}
Else {Write-Host "`t[2] $($immDummy.Param) = $($immDummy.Value)" -ForegroundColor Red}
"`t[2] '$($immDummy.Param)' = '$($immDummy.Value)'" >> $IMMLog
}
#endregion Set IMM Name
#region Upgrade Firmware
### Restart IMM previous to ISO mount to avoid upgrade process fail ###
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tRestarting IMM ... This may take a few minutes" -ForegroundColor Yellow
$immDummy = $null
$immDummy = Restart-IMM -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd -Confirm:$false
If ($immDummy.PowerState -eq 'Restarted') {
$tsTime = Get-CurrentTime
Write-Host "$tsTime`tIMM restarted successfully" -ForegroundColor Green
"$tsTime`tIMM restarted successfully" >> $IMMLog
Start-Sleep -Seconds 120
} Else {Write-Host "$tsTime`tIMM failed to restart, will continue without it" -ForegroundColor Yellow}
### Mount BoMC ISO image to IMM's Virtual Media Drive ###
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tMounting BoMC ISO file to IMM's Virtual Media Drive ..." -ForegroundColor Yellow
If (Get-IMMISO -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd) {Unmount-IMMISO -IMM $IMM}
$immDummy = $null
$immDummy = Mount-IMMISO -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd -ISO $BoMC
If ($immDummy.ISO -ne '') {
Write-Host "$tsTime`tBoMC ISO '$BoMC' successfully mounted" -ForegroundColor Green
"$tsTime`tBoMC ISO '$BoMC' successfully mounted to IMM" >> $IMMLog
} Else {
Write-Host "$tsTime`tFailed to mount BoMC ISO to IMM`n" -ForegroundColor Red
"$tsTime`tFailed to mount BoMC ISO to IMM" >> $IMMLog
### Revert original Boot Order and Exit ###
If ($needChangeBO) {
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tReverting to the Original Boot Order ..." -ForegroundColor Yellow
$immDummy = $null
$immDummy = Set-IMMServerBootOrder -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd -Confirm:$false `
-Boot1 $origBO.Boot1 -Boot2 $origBO.Boot2 -Boot3 $origBO.Boot3 -Boot4 $origBO.Boot4
If ($immDummy.Boot1 -eq $origBO.Boot1) {
Write-Host "$tsTime`tOriginal Boot Order reverted successfully" -ForegroundColor Green
"$tsTime`tOriginal Boot Order reverted successfully" >> $IMMLog
} Else {
Write-Host "$tsTime`tFailed to revert Original Boot Order" -ForegroundColor Red
"$tsTime`tFailed to revert Original Boot Order" >> $IMMLog
}
}
Exit 1
}
### Reboot IBM server ###
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tRebooting IBM server ..." -ForegroundColor Yellow
$immDummy = $null
$immDummy = Reboot-IMMServerOS -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd -Confirm:$false
If ($immDummy.PowerState -eq 'Rebooted') {
Write-Host "$tsTime`tServer successfully rebooted" -ForegroundColor Green
"$tsTime`tServer successfully rebooted" >> $IMMLog
} Else {
Write-Host "$tsTime`tFailed to reboot server`n" -ForegroundColor Red
"$tsTime`tFailed to reboot server" >> $IMMLog
Exit 1
}
### Take a time for Firmware upgrade ###
$waitIMMmin = 40
$waitIMMsec = $waitIMMmin*60
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tWaiting $waitIMMmin minutes for Firmware upgrade to finish ..." -ForegroundColor Yellow
Start-Sleep -Seconds $waitIMMsec
### Waiting for the server to Power Off 1-st time (after IMM upgrade) ###
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tWaiting for server to Power Off ..." -ForegroundColor Yellow
$immDummy = $null
Do
{ Start-Sleep -Seconds 60
$immDummy = Get-IMMServerPowerState -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd
} Until ($immDummy.PowerState -eq 'PoweredOff')
$tsTime = Get-CurrentTime
Write-Host "$tsTime`tIBM Server Powered Off (IMM upgraded)" -ForegroundColor Green
"$tsTime`tIBM Server Powered Off (IMM upgraded)" >> $IMMLog
### Power On the server 1-st time (after IMM upgrade) ###
Start-Sleep -Seconds 120
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tTrying to Power On the server 1-st time ..." -ForegroundColor Yellow
$immDummy = $null
Do
{ Start-IMMServer -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd |Out-Null
Start-Sleep -Seconds 10
$immDummy = Get-IMMServerPowerState -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd
} Until ($immDummy.PowerState -eq 'PoweredOn')
$tsTime = Get-CurrentTime
Write-Host "$tsTime`tIBM Server Powered On (after IMM upgrade)" -ForegroundColor Green
"$tsTime`tIBM Server Powered On (after IMM upgrade)" >> $IMMLog
### Waiting 4 cycles (turned on - turned off) ###
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tWaiting for Host Power 'turned on-turned off' cycles ..." -ForegroundColor Yellow
Start-Sleep -Seconds 900
### Power On the server 2-nd time if not already Powered On (after UEFI upgrade) ###
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tTrying to Power On the server 2-nd time ..." -ForegroundColor Yellow
$immDummy = $null
Do
{ Start-IMMServer -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd
Start-Sleep -Seconds 10
$immDummy = Get-IMMServerPowerState -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd
} Until ($immDummy.PowerState -eq 'PoweredOn')
$tsTime = Get-CurrentTime
Write-Host "$tsTime`tUpgrade finished and IBM Server Powered On" -ForegroundColor Green
"$tsTime`tUpgrade finished and IBM Server Powered On" >> $IMMLog
#endregion Upgrade Firmware
#region Revert to the Original Boot Order
If ($needChangeBO) {
$tsTime = Get-CurrentTime
Write-Host "`n$tsTime`tReverting to the Original Boot Order ..." -ForegroundColor Yellow
$immDummy = $null
$immDummy = Set-IMMServerBootOrder -IMM $IMM -IMMLogin $IMMLogin -IMMPwd $IMMPwd -Confirm:$false `
-Boot1 $origBO.Boot1 -Boot2 $origBO.Boot2 -Boot3 $origBO.Boot3 -Boot4 $origBO.Boot4
If ($immDummy.Boot1 -eq $origBO.Boot1) {
Write-Host "$tsTime`tOriginal Boot Order reverted successfully" -ForegroundColor Green
"$tsTime`tOriginal Boot Order reverted successfully" >> $IMMLog
} Else {
Write-Host "$tsTime`tFailed to revert Original Boot Order" -ForegroundColor Red
"$tsTime`tFailed to revert Original Boot Order" >> $IMMLog
}
}
#endregion Revert to the Original Boot Order