本文是介绍如何使用HP Powershell脚本工具自动更新HP iLO4固件。
运行测试环境是Windows 7 SP1,安装Windows Management Framework 4.0和HP iLO Scripting Tools for Windows PowerShell V1.2.0.3.
做过HP iLO Scripting Tools for Windows PowerShell V1.3.0.x和V1.4.0.x的测试,在cmdlet Find-HPiLO和Get-HPiLO*运行时有错误和结果不准确的问题,还需做进一步的测试。目前V1.2.0.3能满足iLO升级要求,V1.4.0.x运行cmdlet Find-HPiLO时更快。
本实例是以iLO4为例,对iLO3同样适用,只要在脚本中修改相应的iLO固件文件名,并将文件拷贝到C:\Temp中即可。
用Powershell脚本PF-Discover-HPiLO.ps1产生需要更新iLO的服务器的IP地址列表,存放到文件Discovered-HPiLOs-iLO4.txt中,文件中只有IP地址,格式如下:
192.168.4.132
192.168.4.135
192.168.4.136
192.168.4.141
192.168.5.248
192.168.6.251
192.168.8.251
运行一下脚本,就会自动更新所有服务器的iLO固件。
下面是Powershell脚本(HP-iLO4-Auto-Update.ps1):
1 #Requires -Version 3.0 -Modules @{ModuleName='HPiLOCmdlets';ModuleVersion='1.2.0.0'} 2 # ============================================================================================= 3 # This script update iLO4 automatically within a given IP addresses. 4 # The IP addresses come from Discovered-HPiLOs-iLO4.txt. 5 # You can use PF-Discover-HPiLO.ps1 to generate the file or create it manually. 6 # 7 # Author Hinker Liu 8 # email hinkerliu@163.com 9 # Last Modified 2017-August-21 10 # ============================================================================================= 11 Clear-Host 12 13 . .\include\Get-PSCredential.ps1 14 15 $UserName = "username" 16 $PSCredential = Get-PSCredential $UserName 17 $Password = $PSCredential.GetNetworkCredential().Password 18 $TimeOut = 1500 19 20 21 # The IPRange is read from a file which must contain a single IP address per row. 22 # You can use Discover-HPiLO.ps1 to generate the file or create it manually. 23 # 24 $iLOFileName = "C:\Temp\ilo4_254.bin" 25 $InputFileName = "Discovered-HPiLOs-iLO4.txt" 26 $IPRange = Get-Content $InputFileName 27 28 Write-Output "Start to Update iLO boards......" 29 ForEach($IPAddress in $IPRange) 30 { 31 Write-Output "Reading data from $IPAddress" 32 $IsOnline = Find-HPiLO $IPAddress -Timeout $TimeOut 33 If ($IsOnline) 34 { 35 write "Updating HP iLO Firmware of $IPAddress Now......" 36 Update-HPiLOFirmware -Server $IPAddress -Username $Username -Password $Password -TPMEnabled -Location $iLOFileName 37 } 38 Else 39 { 40 Write-Host "[offline] $IPAddress" -ForegroundColor Red 41 } 42 }
下面是Powershell脚本(PF-Discover-HPiLO.ps1):
运行该脚本前先将要搜索的IP地址段保存到文件IPRanges.txt中,并创建五个空文本文件Discovered-HPiLOs-all.txt,Discovered-HPiLOs-UpToDate.txt,Discovered-HPiLOs-iLO2.txt,Discovered-HPiLOs-iLO3.txt,Discovered-HPiLOs-iLO4.txt用来存放搜索结果。
1 #Requires -Version 3.0 -Modules @{ModuleName='HPiLOCmdlets';ModuleVersion='1.2.0.0'} 2 # ============================================================================================= 3 # This script discovers HP iLO, iLO2, iLO3 and iLO4 boards within a given IP ranges. 4 # The resulting list of IP addresses is saved to a file so that you can use it in other scripts. 5 6 # AUTHOR Thomas Franke / sepago GmbH 7 # Blog https://www.sepago.de/thomasf 8 # LASTEDIT 15.10.2015 9 # Modified by Hinker Liu (hinkerliu@163.com) on 2017-August-22 10 # ============================================================================================= 11 Set-StrictMode -Version Latest 12 Clear-Host 13 14 Push-Location $(Split-Path $Script:MyInvocation.MyCommand.Path) 15 16 # A higher timeout improves the detection rate if iLO is connected will less than 1 GBit/s. 17 # Default is 300 milliseconds 18 # 19 $TimeOut = 1500 20 21 # The IPRanges is read from a file for each site per row. 22 # 23 24 $InputFileName = "IPRanges.txt" 25 $IPRanges = Get-Content $InputFileName 26 27 # Latest iLO Version. 28 $NewiLO2Ver = 2.29 29 $NewiLO3Ver = 1.88 30 $NewiLO4Ver = 2.54 31 32 # Discovered-HPiLOs-all.txt for Report. 33 $OutputFileNameAll = "Discovered-HPiLOs-all.txt" 34 $OutputFileNameUpToDate = "Discovered-HPiLOs-UpToDate.txt" 35 $OutputFileNameiLO2 = "Discovered-HPiLOs-iLO2.txt" 36 $OutputFileNameiLO3 = "Discovered-HPiLOs-iLO3.txt" 37 $OutputFileNameiLO4 = "Discovered-HPiLOs-iLO4.txt" 38 39 # Erasing the Contents of a File Discovered-HPiLOs-test.txt. 40 Clear-Content $OutputFileNameAll 41 Clear-Content $OutputFileNameUpToDate 42 Clear-Content $OutputFileNameiLO2 43 Clear-Content $OutputFileNameiLO3 44 Clear-Content $OutputFileNameiLO4 45 46 ForEach($IPRange in $IPRanges) 47 { 48 # Discovering iLO boards 49 # 50 Write-Output "Discovering iLO boards in $IPRange......`n" 51 $FindHPiLO = Find-HPiLO -Range $IPRange -Timeout $TimeOut 52 # If you want to see more detail information, you may use below command line with -Verbose. 53 # $FindHPiLO = Find-HPiLO -Range $IPRange -Timeout $TimeOut -Verbose 54 55 # Save IP address to Output File. 56 # File will be empty if no ralated iLO IP address were found. 57 # 58 59 ForEach ($Record in $FindHPiLO) 60 { 61 If ( ($Record.PN -eq "Integrated Lights-Out 2 (iLO 2)") -And ($Record.FWRI -lt $NewiLO2Ver) ) 62 { 63 $Record.IP | Add-Content -Path $OutputFileNameiLO2 64 $Record.IP | Add-Content -Path $OutputFileNameAll 65 } 66 Elseif ( ($Record.PN -eq "Integrated Lights-Out 3 (iLO 3)") -And ($Record.FWRI -lt $NewiLO3Ver) ) 67 { 68 $Record.IP | Add-Content -Path $OutputFileNameiLO3 69 $Record.IP | Add-Content -Path $OutputFileNameAll 70 } 71 ElseIf ( ($Record.PN -eq "Integrated Lights-Out 4 (iLO 4)") -And ($Record.FWRI -lt $NewiLO4Ver) ) 72 { 73 $Record.IP | Add-Content -Path $OutputFileNameiLO4 74 $Record.IP | Add-Content -Path $OutputFileNameAll 75 } 76 Else 77 { 78 $Record | Add-Content -Path $OutputFileNameUpToDate 79 $Record.IP | Add-Content -Path $OutputFileNameAll 80 } 81 } 82 Write-Output "`n" 83 } 84 Pop-Location