Microsoft Virtualization Discussions

Gathering IOM Shelf Firmware and prepare for large scale Shelf firmware update

JGPSHNTAP
2,085 Views

So, if you guys don't have the luxury of a SAM or are just curious to gather all your IOM Shelf firmware, see the script below.

There are prerequisites of a .csv file with a Filer title.  I get this from an oncommand Dump. (i've written a script to do that in a previous post)

So, the script will ask you to enter the filer list.  Also, this script assumes you are using LDAP Authentication via CIFS to the filer.  If you need to customize it for credentials, feel free. 

From the results of the script, I have another script that will globally update the shelves based on these results.

This script is provided as is, but welcomes comments,updates, and/or suggestions.

<#
.SYNOPSIS
  Collects Shelf Firmware on filers
.DESCRIPTION
  Collects Shelf firmware
.EXAMPLE
  .\Shelf_firmware.ps1
.Notes
  .Author
   Josh Goldfarb
#>


Function main_block {
## Clear screen
cls

## Starting Main
# Importing input file

$hosts = import-csv -path $inputfile

$array = @()

$hosts |  % {
$filer = $_.filer

#$customobject = New-Object psobject
#Add-Member -inputobject $customobject -membertype Noteproperty -name Filer -value $filer

Write-Host "`nConnecting to filer:" $Filer
Try {
$c = connect-nacontroller $filer -erroraction "silentlycontinue"
} catch {
[system.exception] | Out-Null

    }
# Check if connecting to filer


if ($c -ne $null) 
{
###
write-host "`n`t`t`tChecking Shelf Firmware on Filer:" $filer
## Gather Shelf information
$Shelf = Get-NaShelf | ? {$_.type -like "*IOM*"}
## Check for $Null Object
If ($Shelf -ne $Null) {
# Create custom object
## Loop through shelves
         foreach ($s in $Shelf) {
            $customobject = New-Object psobject
         Add-Member -inputobject $customobject -membertype Noteproperty -name Filer -value $filer
   Add-Member -inputobject $customobject -membertype Noteproperty -name "Connected to filer" -value "Yes"
   Add-Member -inputobject $customobject -membertype Noteproperty -name "Shelves Present" -value "Yes" 
   Add-Member -inputobject $customobject -membertype Noteproperty -name Name -value $S.name
   Add-Member -inputobject $customobject -membertype Noteproperty -name Status -value $S.status
   Add-Member -inputobject $customobject -membertype Noteproperty -name "type" -value $S.type
   Add-Member -inputobject $customobject -membertype Noteproperty -name FirmwareA -value $S.FirmwareRevA
   Add-Member -inputobject $customobject -membertype Noteproperty -name Firmwareb -value $S.FirmwareRevb
   $array += $customobject
   }
   } Else {
   Write-Host "`n`t`t`tFiler:" $filer  "Does not have any IOM3 or IOM6 Shelves"
   $customobject = New-Object psobject
   Add-Member -inputobject $customobject -membertype Noteproperty -name Filer -value $filer
   Add-Member -inputobject $customobject -membertype Noteproperty -name "Connected to filer" -value "Yes"
   Add-Member -inputobject $customobject -membertype Noteproperty -name "Shelves Present" -value "NO"
   Add-Member -inputobject $customobject -membertype Noteproperty -name Name -value ""
   Add-Member -inputobject $customobject -membertype Noteproperty -name Status -value ""
   Add-Member -inputobject $customobject -membertype Noteproperty -name "type" -value ""
   Add-Member -inputobject $customobject -membertype Noteproperty -name FirmwareA -value ""
   Add-Member -inputobject $customobject -membertype Noteproperty -name Firmwareb -value ""
   $array += $customobject
   }

   } else  {

    Write-Host "`n`t`t`tCould not connect to filer:" $filer
    $customobject = New-Object psobject
Add-Member -inputobject $customobject -membertype Noteproperty -name Filer -value $filer
    Add-Member -inputobject $customobject -membertype Noteproperty -name "Connected to filer" -value "No"
Add-Member -inputobject $customobject -membertype Noteproperty -name "Shelves Present" -value "NO"
   Add-Member -inputobject $customobject -membertype Noteproperty -name Name -value ""
   Add-Member -inputobject $customobject -membertype Noteproperty -name Status -value ""
   Add-Member -inputobject $customobject -membertype Noteproperty -name "type" -value ""
   Add-Member -inputobject $customobject -membertype Noteproperty -name FirmwareA -value ""
   Add-Member -inputobject $customobject -membertype Noteproperty -name Firmwareb -value ""
    $array += $customobject
}
   #$array += $customobject

Clear-Variable c
clear-variable filer

}
  $2day = (get-date).tostring("MM-dd-yyyy-hh_mm")
$array | Export-Csv c:\temp\shelfinformation_$2day.csv -NoTypeInformation
$array | ft -autosize

### Close Main Function
}

cls
$Host.UI.RAWUI.WindowTitle="Shelf Firmware Checker"

If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
cls
Write-Warning -Message "`nYou are attempting to execute this script in an non-elevated shell.
This script requires to be run under Administrator priviledge.
Please Re-launch Powershell as Administrator."
"`n"
"`n"
Timeout /t -1
cls
Exit
}
write-host "`n"
$inputfile = read-host "Please enter an input file of a list of Filers you want to check Shelf Firmware on (i.e. c:\temp\filers.csv)"

$fileloctest = test-path $inputfile

If ($fileloctest -eq $false) {
cls
Write-Warning -Message "`nLocation of the file cannot be found.
Please check the path of the file and re-execute.
Exiting Script."
"`n"
"`n"
Timeout /t -1
Exit
}

## Clear screen
cls

$title = "Shelf Firmware Checker"
$message = @"
`nBefore the script executes we want to ensure that you have entered the proper information:
`n
`t`t`t`t`t`t`tThe input file you entered is: $inputfile
`t`t`t`t`t`t`tInput File's path has been confirmed: $fileloctest
`n
`t`t`t`t`t`t`tIf these are both correct, please (P)roceed  If this is not correct, please (e)xit
"@
  

$proceed= New-Object System.Management.Automation.Host.ChoiceDescription "&Proceed", `
    "(P)roceed with Shelf Firmware Check"

$exit =   New-Object System.Management.Automation.Host.ChoiceDescription "&exit",
"Type exit or (E) to exit the script"

$options = [System.Management.Automation.Host.ChoiceDescription[]]($proceed,$exit)

$result = $host.ui.PromptForChoice($title, $message, $options, 1)

switch ($result)
    {
        0 {
   # Selected to proceed to password change
            main_block
      }
       
          

        1
        ## Exiting Script
        {
       
        Write-Host "`nYou have selected Exit`n"
        timeout /t -1
  cls
        Exit 
          }
    }
   

1 REPLY 1

vinith
2,085 Views

Nice stuff!!

Public