Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <# script to check for ilo firmware updates #>
  2.  
  3.  
  4. param (
  5.     [parameter(Mandatory = $true, Helpmessage = "Enter the firmware version to check if ilos are up to date.")] #user must supply a param.
  6.     [decimal]$firmware = "",
  7.     [parameter(Mandatory = $true, Helpmessage = "Enter the file location of the firmware file you wish to update to ending in .bin.")]
  8.     [string]$firmwareFile =""
  9. )
  10.  
  11.  
  12.  
  13. #Variables
  14. $ilos = get-content updateServers.txt #use an argument to allow user to select a different file location .txt    
  15. $pingTest = ""
  16. $activeIlos = @()
  17. $iloCredential = Get-Credential -Message "Please input username and password"
  18. $currentUser = ""
  19. $currentVersion = ""
  20. $versionNumber = ""
  21. #$firmwareFile = ""
  22. #[decimal]$firmware = ""
  23. $dateTime = get-date
  24. $updateilos = ""
  25.  
  26. #can add in params with [switch]$statement for true or false, if -paramaeter is provided it will be true
  27.  
  28.  
  29. function versionCheck
  30. {
  31. foreach ($ilo in $ilos) {
  32.  
  33. #checks if host is running by pinging, if server pings, add to active ilos
  34.  
  35.         $pingTest = Test-Connection -ComputerName $ilo -errorAction 'Silentlycontinue'
  36.             if ($pingTest) {
  37.               write-host iLO: $ilo 'is online - checking for current firmware version.'  
  38.  
  39.                 $currentVersion = Get-HPiLOFirmwareVersion -Server $ilo -Credential $iloCredential -errorAction 'Silentlycontinue' -DisableCertificateAuthentication | select-object firmware_version
  40.                 $versionNumber = $currentVersion."FIRMWARE_VERSION"     #gets firmware version from string
  41.                 write-host currently running firmware: $versionNumber
  42.  
  43.                       } else {
  44.                   write-host Cannot connect to $ilo.
  45.                 }  
  46.            
  47.                 if ($versionNumber -lt $Firmware) {
  48.                 $updateilos += $ilo    
  49.                 $updateilos += ","
  50.                                  #adds to a list of ilos that require updates.
  51.                 write-host Firmware requires updating.  
  52.                 write-host $updateilos
  53.                
  54.                 }
  55.               }
  56.  
  57. }
  58.  
  59. function Menu1
  60. {
  61. write-host "Are the following details correct?"    
  62. write-host "Firmware Version: $firmware"
  63. write-host "File Location $firmwareFile"
  64.  
  65. write-host "=============== Please Select an Option ==============="
  66.  
  67.   write-host "1: Yes, view current iLO firmware "
  68.  
  69.   write-host "2: No, change"
  70.  
  71.   write-host "3: Quit"
  72.  
  73.  
  74. }
  75.  
  76. function Menu2
  77. {
  78. write-host "=============== Please Select an Option ==============="
  79.  
  80.   write-host "1: Update all ilo firmware less than $firmware "
  81.  
  82.   write-host "2: Select a specific ilo to update to $firmware"
  83.  
  84.   write-host "3: Re-run iLO version check"
  85.  
  86.   write-host "4: Quit"
  87. }
  88.  
  89. #function TrimArray
  90. #{
  91.     #char 44 is ascii for a comma
  92. #$updateilos = $updateilos.Substring(0,$updateilos.Length-1)
  93. #$updateilos[-1] = $updateilos[-1].TrimEnd([char]',')      #trims last
  94.  
  95. #}
  96.  
  97. #END OF VARS AND FUNCTIONS
  98.  
  99. #create arguments rather than read host. parameters???
  100. #https://mcpmag.com/articles/2015/04/09/use-powershell-parameters.aspx
  101.  
  102.     foreach ($ilo in $ilos) {
  103.     write-host $ilo
  104.  
  105. }
  106.  
  107.  
  108.  
  109.   while (($yesNo = read-host -prompt "Do you wish to check firmware versions of the above ilos? { y / n }" ) -ne "n") {
  110.    if ($yesNo = "y", "yes") {
  111.        versionCheck
  112.             }
  113.                
  114.               #If current version of firmware is < new version prompt to update
  115.  
  116.               #switch statement for the following options rather than if's.
  117.  
  118.         do   #add a cls before the switch
  119.           {
  120.            
  121.             Menu2
  122.             $options = Read-Host "Please Select"
  123.               switch($options) {
  124.  
  125.             '1'{ cls            
  126.                                                 #Updates all ilos to ilo file saved in variable
  127.                             #foreach ($ilo in $updateilos) {
  128.                                                 #$updateilos = $updateilos.Substring(0,$updateilos.Length-1)  
  129.                                                 $connectilo = connect-HPEilo -IP $updateilos -Credential $iloCredential -DisableCertificateAuthentication #-errorAction 'Silentlycontinue' -WarningAction 'Silentlycontinue' -Confirm:$false
  130.                                                 update-HPEiLOFirmware -connection $connectilo -Location $firmwareFile #-errorAction 'Silentlycontinue' -WarningAction 'Silentlycontinue' -Confirm:$false
  131.                                                 write-host Firmware will now update, this may take a few minutes.}
  132.  
  133.                '2' { cls                        #select a specific ilo to update to firmware saved in $firmwarefile above.
  134.                                                 write-host Select a specific iLO to update to $firmware
  135.                                                 $iloSelect = Read-host "Enter the host name of the iLO you would like to update"
  136.                                                 $connectilo = connect-HPEilo -IP $iloSelect -Credential $iloCredential -DisableCertificateAuthentication
  137.                                                 update-HPEiLOFirmware -connection $connectilo -Location $firmwareFile
  138.                                                 write-host Firmware will now update, this may take a few minutes.}
  139.                                                 #add a back option
  140.                
  141.                '3' {                            versionCheck      #runs function
  142.                }
  143.                                              
  144.                          
  145.                 '4'   {  cls  exit-PSsession   } #quit
  146.              
  147.               }  }
  148.                  until($options -eq 4 )
  149.              
  150.    }
  151. #Logging
  152. #Updated Ilos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement