Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <# script to check for ilo firmware updates #>
- param (
- [parameter(Mandatory = $true, Helpmessage = "Enter the firmware version to check if ilos are up to date.")] #user must supply a param.
- [decimal]$firmware = "",
- [parameter(Mandatory = $true, Helpmessage = "Enter the file location of the firmware file you wish to update to ending in .bin.")]
- [string]$firmwareFile =""
- )
- #Variables
- $ilos = get-content updateServers.txt #use an argument to allow user to select a different file location .txt
- $pingTest = ""
- $activeIlos = @()
- $iloCredential = Get-Credential -Message "Please input username and password"
- $currentUser = ""
- $currentVersion = ""
- $versionNumber = ""
- #$firmwareFile = ""
- #[decimal]$firmware = ""
- $dateTime = get-date
- $updateilos = ""
- #can add in params with [switch]$statement for true or false, if -paramaeter is provided it will be true
- function versionCheck
- {
- foreach ($ilo in $ilos) {
- #checks if host is running by pinging, if server pings, add to active ilos
- $pingTest = Test-Connection -ComputerName $ilo -errorAction 'Silentlycontinue'
- if ($pingTest) {
- write-host iLO: $ilo 'is online - checking for current firmware version.'
- $currentVersion = Get-HPiLOFirmwareVersion -Server $ilo -Credential $iloCredential -errorAction 'Silentlycontinue' -DisableCertificateAuthentication | select-object firmware_version
- $versionNumber = $currentVersion."FIRMWARE_VERSION" #gets firmware version from string
- write-host currently running firmware: $versionNumber
- } else {
- write-host Cannot connect to $ilo.
- }
- if ($versionNumber -lt $Firmware) {
- $updateilos += $ilo
- $updateilos += ","
- #adds to a list of ilos that require updates.
- write-host Firmware requires updating.
- write-host $updateilos
- }
- }
- }
- function Menu1
- {
- write-host "Are the following details correct?"
- write-host "Firmware Version: $firmware"
- write-host "File Location $firmwareFile"
- write-host "=============== Please Select an Option ==============="
- write-host "1: Yes, view current iLO firmware "
- write-host "2: No, change"
- write-host "3: Quit"
- }
- function Menu2
- {
- write-host "=============== Please Select an Option ==============="
- write-host "1: Update all ilo firmware less than $firmware "
- write-host "2: Select a specific ilo to update to $firmware"
- write-host "3: Re-run iLO version check"
- write-host "4: Quit"
- }
- #function TrimArray
- #{
- #char 44 is ascii for a comma
- #$updateilos = $updateilos.Substring(0,$updateilos.Length-1)
- #$updateilos[-1] = $updateilos[-1].TrimEnd([char]',') #trims last
- #}
- #END OF VARS AND FUNCTIONS
- #create arguments rather than read host. parameters???
- #https://mcpmag.com/articles/2015/04/09/use-powershell-parameters.aspx
- foreach ($ilo in $ilos) {
- write-host $ilo
- }
- while (($yesNo = read-host -prompt "Do you wish to check firmware versions of the above ilos? { y / n }" ) -ne "n") {
- if ($yesNo = "y", "yes") {
- versionCheck
- }
- #If current version of firmware is < new version prompt to update
- #switch statement for the following options rather than if's.
- do #add a cls before the switch
- {
- Menu2
- $options = Read-Host "Please Select"
- switch($options) {
- '1'{ cls
- #Updates all ilos to ilo file saved in variable
- #foreach ($ilo in $updateilos) {
- #$updateilos = $updateilos.Substring(0,$updateilos.Length-1)
- $connectilo = connect-HPEilo -IP $updateilos -Credential $iloCredential -DisableCertificateAuthentication #-errorAction 'Silentlycontinue' -WarningAction 'Silentlycontinue' -Confirm:$false
- update-HPEiLOFirmware -connection $connectilo -Location $firmwareFile #-errorAction 'Silentlycontinue' -WarningAction 'Silentlycontinue' -Confirm:$false
- write-host Firmware will now update, this may take a few minutes.}
- '2' { cls #select a specific ilo to update to firmware saved in $firmwarefile above.
- write-host Select a specific iLO to update to $firmware
- $iloSelect = Read-host "Enter the host name of the iLO you would like to update"
- $connectilo = connect-HPEilo -IP $iloSelect -Credential $iloCredential -DisableCertificateAuthentication
- update-HPEiLOFirmware -connection $connectilo -Location $firmwareFile
- write-host Firmware will now update, this may take a few minutes.}
- #add a back option
- '3' { versionCheck #runs function
- }
- '4' { cls exit-PSsession } #quit
- } }
- until($options -eq 4 )
- }
- #Logging
- #Updated Ilos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement