Skip to content

Instantly share code, notes, and snippets.

@mo6020
Created April 2, 2014 15:27
Show Gist options
  • Save mo6020/9936395 to your computer and use it in GitHub Desktop.
Save mo6020/9936395 to your computer and use it in GitHub Desktop.
Pull UCS serial numbers
##################################################
# Joe Martin
# Cisco Systems, Inc.
# UCS Serial Number Collector v0.8
# 3/10/13
#
# Code provided as-is. No warranty implied or included.
# This code is for example use only and not for production
#
# This script will create an excel file of all UCSM based
# devices and their serial numbers.
#
##################################################
#Setup PowerShell console colors for compatibility with my script colors
$PowerShellWindow = (Get-Host).UI.RawUI
$PowerShellWindow.BackgroundColor = "White"
$PowerShellWindow.ForegroundColor = "Black"
#Clear the screen
clear-host
#Script kicking off
Write-Host -ForegroundColor White -BackgroundColor DarkBlue "Script Running..."
#Tell the user what the script does
Write-Host ""
Write-Host -ForegroundColor DarkBlue "This script allows you to log into a single or multiple UCS Domains and it will create an Excel spreadsheet of all"
Write-Host -ForegroundColor DarkBlue "the devices and their serial number along with other relevant associated information"
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Prerequisites:"
Write-Host -ForegroundColor DarkMagenta " PowerShell v3 enabled on your client machine"
Write-Host -ForegroundColor DarkMagenta " Network access to your UCSM"
Write-Host -ForegroundColor DarkMagenta " An account on your UCSM"
Write-Host -ForegroundColor DarkMagenta " Excel installed on the client machine"
Write-Host -ForegroundColor DarkMagenta " Cisco PowerTool for PowerShell installed in the client machine. It can be downloaded at http:\\www.cisco.com"
#Do not show errors in script
$ErrorActionPreference = "SilentlyContinue"
#$ErrorActionPreference = "Stop"
#$ErrorActionPreference = "Continue"
#$ErrorActionPreference = "Inquire"
#Verify PowerShell Version for script support
$PSVersion = $psversiontable.psversion
$PSMinimum = $PSVersion.Major
if ($PSMinimum -ge "3")
{
}
else
{
Write-Host -ForegroundColor Red "This script requires PowerShell version 3 or above"
Write-Host -ForegroundColor Red "Please update your system and try again."
Write-Host -ForegroundColor Red "You can download PowerShell updates here:"
Write-Host -ForegroundColor Red " http://search.microsoft.com/en-us/DownloadResults.aspx?rf=sp&q=powershell+4.0+download"
Write-Host -ForegroundColor Red "If you are running a version of Windows before 7 or Server 2008R2 you need to update to be supported"
Write-Host -ForegroundColor Red " Exiting..."
Disconnect-Ucs
exit
}
#Load the UCS PowerTool
Write-Host -ForegroundColor DarkBlue "Checking Cisco PowerTool"
$PowerToolLoaded = $null
$Modules = Get-Module
$PowerToolLoaded = $modules.name
if ( -not ($Modules -like "ciscoUcsPs"))
{
Write-Host -ForegroundColor DarkBlue " Loading Module: Cisco UCS PowerTool Module"
Import-Module ciscoUcsPs
$Modules = Get-Module
if ( -not ($Modules -like "ciscoUcsPs"))
{
Write-Host ""
Write-Host -ForegroundColor Red " Cisco UCS PowerTool Module did not load. Please correct his issue and try again"
Write-Host -ForegroundColor Red " Exiting..."
exit
}
else
{
Write-Host -ForegroundColor DarkGreen " PowerTool is Loaded"
}
}
else
{
Write-Host -ForegroundColor DarkGreen " PowerTool is Loaded"
}
#Define UCS Domain(s)
$myucs = Read-Host "Enter UCS system IP or Hostname or a list of systems separated by comma"
[array]$myucs = ($myucs.split(",")).trim()
if ($myucs.count -eq 0)
{
Write-Host
Write-Host -ForegroundColor Red "You didn't enter anything"
Write-Host -ForegroundColor Red " Exiting..."
Disconnect-Ucs
exit
}
#Make sure we are disconnected from other UCS Systems
Disconnect-Ucs
#Test that UCSM is IP Reachable via Ping
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Testing PING access to UCSM"
foreach ($ucs in $myucs)
{
$ping = new-object system.net.networkinformation.ping
$results = $ping.send($ucs)
if ($results.Status -ne "Success")
{
Write-host -ForegroundColor Red " Can not access UCSM $ucs by Ping"
Write-Host ""
Write-Host -ForegroundColor DarkCyan "It is possible that a firewall is blocking ICMP (PING) Access. Would you like to try to log in anyway?"
$Try = Read-Host "Would you like to try to log in anyway? (Y/N)"
if ($Try -ieq "y")
{
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Trying to log in anyway!"
Write-Host ""
}
elseif ($Try -ieq "n")
{
Write-Host ""
Write-Host -ForegroundColor DarkBlue "You have chosen to exit"
Write-Host -ForegroundColor DarkBlue " Exiting..."
Disconnect-Ucs
exit
}
else
{
Write-Host ""
Write-Host -ForegroundColor Red "You have provided invalid input"
Write-Host -ForegroundColor Red " Exiting..."
Write-Host ""
Disconnect-Ucs
exit
}
}
else
{
Write-host -ForegroundColor DarkGreen " Successful access to $ucs by Ping"
Write-Host ""
}
}
#Log into the UCS System
$multilogin = Set-UcsPowerToolConfiguration -SupportMultipleDefaultUcs $true
Write-Host -ForegroundColor DarkBlue "Logging into UCS"
Write-Host -ForegroundColor DarkCyan " Enter your UCSM credentials"
#Verify PowerShell Version to pick prompt type
$PSVersion = $psversiontable.psversion
$PSMinimum = $PSVersion.Major
if ($PSMinimum -ge "3")
{
$cred = Get-Credential -Message "UCSM(s) Login Credentials" -UserName "admin"
}
else
{
$cred = Get-Credential
}
foreach ($myucslist in $myucs)
{
Write-Host -ForegroundColor DarkBlue "logging into:"$myucslist
$myCon = $null
$myCon = Connect-Ucs $myucslist -Credential $cred
if (($mycon).Name -ne ($myucslist))
{
#Exit Script
Write-Host -ForegroundColor Red " Error Logging into this UCS domain"
if ($myucs.count -le 1)
{
$continue = "n"
}
else
{
$continue = Read-Host "Continue without this UCS domain (Y/N)"
}
if ($continue -ieq "n")
{
Write-Host -ForegroundColor DarkBlue "Exiting Script..."
Disconnect-Ucs
exit
}
else
{
Write-Host -ForegroundColor DarkBlue " Continuing..."
}
}
else
{
Write-Host -ForegroundColor DarkGreen " Login Successful"
}
sleep 1
}
if ($myCon.count -eq 0)
{
Write-Host ""
Write-Host -ForegroundColor Red "You are not logged into any UCSM systems"
Write-Host -ForegroundColor Red " Exiting..."
Disconnect-Ucs
exit
}
#Launch Excel application
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Launching Excel in the background (Hidden)"
$Excel = New-Object -comobject Excel.Application
#Keeps Excel hidden in the background
$Excel.Visible = $False
#Create a new Excel workbook
Write-Host -ForegroundColor DarkBlue " Creating new workbook"
$Workbook = $Excel.Workbooks.Add()
#Create a new Excel worksheet
$Worksheet += $Workbook.Worksheets.Item(1)
#Rename the Excel worksheet
Write-Host -ForegroundColor DarkBlue " Creating worksheet: Serial Numbers"
$Worksheet.Name = "Serial Numbers"
#Create Excel headers
Write-Host -ForegroundColor DarkBlue " Setting worksheet headers"
$Worksheet.Cells.Item(1,1) = "Category"
$Worksheet.Cells.Item(1,2) = "UCS Domain"
$Worksheet.Cells.item(1,3) = "Name"
$Worksheet.Cells.item(1,4) = "Service Profile"
$Worksheet.Cells.item(1,5) = "Model Number"
$Worksheet.Cells.item(1,6) = "Serial Number"
$Worksheet.Cells.item(1,7) = "MFG Date"
#Format Excel cell headers
Write-Host -ForegroundColor DarkBlue " Formatting cells"
$Worksheet.Cells.item(1,1).font.size=12
$Worksheet.Cells.item(1,1).font.bold=$true
$Worksheet.Cells.item(1,1).font.underline=$true
$Worksheet.Cells.item(1,2).font.size=12
$Worksheet.Cells.item(1,2).font.bold=$true
$Worksheet.Cells.item(1,2).font.underline=$true
$Worksheet.Cells.item(1,3).font.size=12
$Worksheet.Cells.item(1,3).font.bold=$true
$Worksheet.Cells.item(1,3).font.underline=$true
$Worksheet.Cells.item(1,4).font.size=12
$Worksheet.Cells.item(1,4).font.bold=$true
$Worksheet.Cells.item(1,4).font.underline=$true
$Worksheet.Cells.item(1,5).font.size=12
$Worksheet.Cells.item(1,5).font.bold=$true
$Worksheet.Cells.item(1,5).font.underline=$true
$Worksheet.Cells.item(1,6).font.size=12
$Worksheet.Cells.item(1,6).font.bold=$true
$Worksheet.Cells.item(1,6).font.underline=$true
$Worksheet.Cells.item(1,7).font.size=12
$Worksheet.Cells.item(1,7).font.bold=$true
$Worksheet.Cells.item(1,7).font.underline=$true
$Worksheet.columns.item(1).columnWidth = 30
$Worksheet.columns.item(2).columnWidth = 35
$Worksheet.columns.item(3).columnWidth = 45
$Worksheet.columns.item(4).columnWidth = 35
$Worksheet.columns.item(5).columnWidth = 40
$Worksheet.columns.item(6).columnWidth = 25
$Worksheet.columns.item(7).columnWidth = 25
#Gather info from UCS
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Gathering information from UCSM" -NoNewline
$FIs = Get-UcsNetworkElement | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,RN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$FIModules = Get-UcsFiModule | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Chassis = Get-UcsChassis | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$IOM = Get-UcsIom | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$FEX = Get-UcsFex | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Blade = Get-UcsBlade | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Rack = Get-UcsRackUnit | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Adapter = Get-UcsAdaptorUnit | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$AdapterExpansion = Get-UcsAdaptorUnitExtn | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$DIMMs = Get-UcsMemoryUnit | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null) -and ($_.Serial -ne "NO DIMM"))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$StorageController = Get-UcsStorageController | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Storage = Get-UcsStorageLocalDisk | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Fan = Get-UcsFan | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,MfgTime,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$PSU = Get-UcsPSU | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Disk = Get-UcsStorageLocalDisk | where {(($_.Serial -ne "") -and ($_.Serial -ne "N/A") -and ($_.Serial -ne $null))} | Sort-Object -CaseSensitive -Property Ucs,DN,Model,Serial
Write-Host -ForegroundColor DarkBlue "." -NoNewline
Write-Host ""
#Put important data into tables
Write-Host -ForegroundColor DarkBlue " Creating tables of data" -NoNewline
$FITable = @{"UCS" = $FIs.Ucs ; "DN" = $FIs.RN ; "Model" = $FIs.Model ; "Serial" = $FIs.Serial ; "ServiceProfile" = "N/A" ; "MfgTime" = $FIs.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$FIModuleTable = @{"UCS" = $FIModules.Ucs ; "DN" = $FIModules.Dn ; "Model" = $FIModules.Model ; "Serial" = $FIModules.Serial ; "ServiceProfile" = "N/A" ; "MfgTime" = $FIModules.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$ChassisTable = @{"UCS" = $Chassis.Ucs ; "DN" = $Chassis.Dn ; "Model" = $Chassis.Model ; "Serial" = $Chassis.Serial ; "ServiceProfile" = "N/A" ; "MfgTime" = $Chassis.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$IOMTable = @{"UCS" = $IOM.Ucs ; "DN" = $IOM.Dn ; "Model" = $IOM.Model ; "Serial" = $IOM.Serial ; "ServiceProfile" = "N/A" ; "MfgTime" = $IOM.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$FEXTable = @{"UCS" = $FEX.Ucs ; "DN" = $FEX.Dn ; "Model" = $FEX.Model ; "Serial" = $FEX.Serial ; "ServiceProfile" = "N/A" ; "MfgTime" = $FEX.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$BladeTable = @{"UCS" = $Blade.Ucs ; "DN" = $Blade.Dn ; "Model" = $Blade.Model ; "Serial" = $Blade.Serial ; "ServiceProfile" = $Blade.AssignedToDn ; "MfgTime" = $Blade.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$RackTable = @{"UCS" = $Rack.Ucs ; "DN" = $Rack.Dn ; "Model" = $Rack.Model ; "Serial" = $Rack.Serial ; "ServiceProfile" = $Rack.AssignedToDn ; "MfgTime" = $Rack.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$AdapterLoop = ($Adapter.Dn).count
$Loop = 1
$SPArray = @()
do
{
$BladeFull = $Adapter.Dn[$Loop - 1] -match "(?<content>.*)/adaptor-"
$BladeReadable = $matches['content']
$ServiceProfile = Get-UcsServiceProfile -Ucs $Adapter.Ucs[$Loop - 1] -PnDn $BladeReadable
if ($ServiceProfile -eq $null)
{
$SPArray += "<<UNASSOCIATED>>"
}
else
{
$SPArray += $ServiceProfile.Name
}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Loop++
}
while
(
$Loop -le $AdapterLoop
)
$AdapterTable = @{"UCS" = $Adapter.Ucs ; "DN" = $Adapter.Dn ; "Model" = $Adapter.Model ; "Serial" = $Adapter.Serial ; "ServiceProfile" = $SPArray ; "MfgTime" = $Adapter.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$AdapterExpansionLoop = ($AdapterExpansion.Dn).count
$Loop = 1
$SPArray = @()
do
{
$AdapterExpansionFull = $AdapterExpansion.Dn[$Loop - 1] -match "(?<content>.*)/adaptor-[0-9]"
$AdapterExpansionReadable = $matches['content']
$ServiceProfile = Get-UcsServiceProfile -Ucs $AdapterExpansion.Ucs[$Loop - 1] -PnDn $AdapterExpansionReadable
if ($ServiceProfile -eq $null)
{
$SPArray += "<<UNASSOCIATED>>"
}
else
{
$SPArray += $ServiceProfile.Name
}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Loop++
}
while
(
$Loop -le $AdapterExpansionLoop
)
$AdapterExpansionTable = @{"UCS" = $AdapterExpansion.Ucs ; "DN" = $AdapterExpansion.Dn ; "Model" = $AdapterExpansion.Model ; "Serial" = $AdapterExpansion.Serial ; "ServiceProfile" = $SPArray ; "MfgTime" = $AdapterExpansion.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$DIMMsLoop = ($DIMMs.Dn).count
$Loop = 1
$SPArray = @()
do
{
$DIMMsFull = $DIMMs.Dn[$Loop - 1] -match "(?<content>.*)/board"
$DIMMsReadable = $matches['content']
$ServiceProfile = Get-UcsServiceProfile -Ucs $DIMMs.Ucs[$Loop - 1] -PnDn $DIMMsReadable
if ($ServiceProfile -eq $null)
{
$SPArray += "<<UNASSOCIATED>>"
}
else
{
$SPArray += $ServiceProfile.Name
}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Loop++
}
while
(
$Loop -le $DIMMsLoop
)
$DIMMsTable = @{"UCS" = $DIMMs.Ucs ; "DN" = $DIMMs.Dn ; "Model" = $DIMMs.Model ; "Serial" = $DIMMs.Serial ; "ServiceProfile" = $SPArray ; "MfgTime" = $DIMMs.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$StorageControllerLoop = ($StorageController.Dn).count
$Loop = 1
$SPArray = @()
do
{
$StorageControllerFull = $StorageController.Dn[$Loop - 1] -match "(?<content>.*)/board"
$StorageControllerReadable = $matches['content']
$ServiceProfile = Get-UcsServiceProfile -Ucs $StorageController.Ucs[$Loop - 1] -PnDn $StorageControllerReadable
if ($ServiceProfile -eq $null)
{
$SPArray += "<<UNASSOCIATED>>"
}
else
{
$SPArray += $ServiceProfile.Name
}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Loop++
}
while
(
$Loop -le $StorageControllerLoop
)
$StorageControllerTable = @{"UCS" = $StorageController.Ucs ; "DN" = $StorageController.Dn ; "Model" = $StorageController.Model ; "Serial" = $StorageController.Serial ; "ServiceProfile" = $SPArray ; "MfgTime" = $StorageController.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$StorageLoop = ($Storage.Dn).count
$Loop = 1
$SPArray = @()
do
{
$StorageFull = $Storage.Dn[$Loop - 1] -match "(?<content>.*)/board"
$StorageReadable = $matches['content']
$ServiceProfile = Get-UcsServiceProfile -Ucs $Storage.Ucs[$Loop - 1] -PnDn $StorageReadable
if ($ServiceProfile -eq $null)
{
$SPArray += "<<UNASSOCIATED>>"
}
else
{
$SPArray += $ServiceProfile.Name
}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Loop++
}
while
(
$Loop -le $StorageLoop
)
$StorageTable = @{"UCS" = $Storage.Ucs ; "DN" = $Storage.Dn ; "Model" = $Storage.Model ; "Serial" = $Storage.Serial ; "ServiceProfile" = $SPArray ; "MfgTime" = $Storage.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$FanTable = @{"UCS" = $Fan.Ucs ; "DN" = $Fan.Dn ; "Model" = $Fan.Model ; "Serial" = $Fan.Serial ; "MfgTime" = $Fan.MfgTime}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$PSULoop = ($PSU.Dn).count
$Loop = 1
$SPArray = @()
do
{
$PSUFull = $PSU.Dn[$Loop - 1] -match "(?<content>.*)/psu"
$PSUReadable = $matches['content']
$ServiceProfile = Get-UcsServiceProfile -Ucs $PSU.Ucs[$Loop - 1] -PnDn $PSUReadable
if (($ServiceProfile -eq $null) -and ($PSUReadable.SubString(0,7) -eq "sys/rac"))
{
$SPArray += "<<UNASSOCIATED>>"
}
elseif ($ServiceProfile -ne $null)
{
$SPArray += $ServiceProfile.Name
}
else
{
$SPArray += "N/A"
}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Loop++
}
while
(
$Loop -le $PSULoop
)
$PSUTable = @{"UCS" = $PSU.Ucs ; "DN" = $PSU.Dn ; "Model" = $PSU.Model ; "Serial" = $PSU.Serial ; "ServiceProfile" = $SPArray ; "MfgTime" = $PSU.MfgTime}
#------
$DiskLoop = ($Disk.Dn).count
$Loop = 1
$SPArray = @()
do
{
$DiskFull = $Disk.Dn[$Loop - 1] -match "(?<content>.*)/board"
$DiskReadable = $matches['content']
$ServiceProfile = Get-UcsServiceProfile -Ucs $Disk.Ucs[$Loop - 1] -PnDn $DiskReadable
if ($ServiceProfile -eq $null)
{
$SPArray += "<<UNASSOCIATED>>"
}
elseif ($ServiceProfile -ne $null)
{
$SPArray += $ServiceProfile.Name
}
else
{
$SPArray += "N/A"
}
Write-Host -ForegroundColor DarkBlue "." -NoNewline
$Loop++
}
while
(
$Loop -le $DiskLoop
)
$DiskTable = @{"UCS" = $Disk.Ucs ; "DN" = $Disk.Dn ; "Model" = $Disk.Model ; "Serial" = $Disk.Serial ; "ServiceProfile" = $SPArray ; "MfgTime" = "N/A"}
#------
Write-Host -ForegroundColor DarkBlue "." -NoNewline
Write-Host ""
#Setting values for data formatting
$Loop = 1
$FILoop = $FITable.UCS.Count
$FIModuleLoop = $FIModuleTable.UCS.Count
$ChassisLoop = $ChassisTable.UCS.Count
$IOMLoop = $IOMTable.UCS.Count
$FEXLoop = $FEXTable.UCS.Count
$BladeLoop = $BladeTable.UCS.Count
$RackLoop = $RackTable.UCS.Count
$AdapterLoop = $AdapterTable.UCS.Count
$AdapterExpansionLoop = $AdapterExpansionTable.UCS.Count
$DIMMsLoop = $DIMMsTable.UCS.Count
$StorageControllerLoop = $StorageControllerTable.UCS.Count
$StorageLoop = $StorageTable.UCS.Count
$FanLoop = $FanTable.UCS.Count
$PSULoop = $PSUTable.UCS.Count
#Writing Fabric Interconnect information to Excel
if ($FILoop -ne 0)
{
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing Fabric Interconnect information to Excel" -NoNewline
$DoLoop = 1
$Worksheet.Cells.item($Loop+1,1) = "'Fabric Interconnect(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($FILoop -eq 1)
{
$Worksheet.Cells.Item($Loop+1,2) = "'"+$FITable.UCS #UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$FITable.DN #Name
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$FITable.Model #Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$FITable.Serial #Serial
if (($FITable.MfgTime -eq "") -or ($FITable.MfgTime -eq $null) -or ($FITable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($FITable.MfgTime -replace "T", " ") #Manufacturing Time
}
$Loop += 1
$DoLoop += 1
}
else
{
$Worksheet.Cells.Item($Loop+1,2) = "'"+$FITable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$FITable.DN[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$FITable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$FITable.Serial[$DoLoop-1]
if ($FITable.MfgTime.Count -ne 0)
{
if (($FITable.MfgTime[$DoLoop-1] -eq "") -or ($FITable.MfgTime[$DoLoop-1] -eq $null) -or ($FITable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($FITable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $FILoop)
}
#Writing Fabric Interconnect Module information to Excel
if ($FIModuleLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing Fabric Interconnect Module information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'Fabric Interconnect Module(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($FIModuleLoop -eq 1)
{
$DNFull = $FIModuleTable.DN -match "/(?<content>.*)/"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$FIModuleTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$FIModuleTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$FIModuleTable.Serial
if (($FIModuleTable.MfgTime -eq "") -or ($FIModuleTable.MfgTime -eq $null) -or ($FIModuleTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($FIModuleTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $FIModuleTable.DN[$DoLoop-1] -match "/(?<content>.*)/"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$FIModuleTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$FIModuleTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$FIModuleTable.Serial[$DoLoop-1]
if ($FIModuleTable.MfgTime.Count -ne 0)
{
if (($FIModuleTable.MfgTime[$DoLoop-1] -eq "") -or ($FIModuleTable.MfgTime[$DoLoop-1] -eq $null) -or ($FIModuleTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($FIModuleTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $FIModuleLoop)
}
#Writing Chassis information to Excel
if ($ChassisLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing Chassis information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'Chassis(')"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($ChassisLoop -eq 1)
{
$DNFull = $ChassisTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$ChassisTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$ChassisTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$ChassisTable.Serial
if (($ChassisTable.MfgTime -eq "") -or ($ChassisTable.MfgTime -eq $null) -or ($ChassisTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($ChassisTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $ChassisTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$ChassisTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$ChassisTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$ChassisTable.Serial[$DoLoop-1]
if ($ChassisTable.MfgTime.Count -ne 0)
{
if (($ChassisTable.MfgTime[$DoLoop-1] -eq "") -or ($ChassisTable.MfgTime[$DoLoop-1] -eq $null) -or ($ChassisTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($ChassisTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $ChassisLoop)
}
#Writing IOM information to Excel
if ($IOMLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing IOM information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'IOM(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($IOMLoop -eq 1)
{
$DNFull = $IOMTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$IOMTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$IOMTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$IOMTable.Serial
if (($IOMTable.MfgTime -eq "") -or ($IOMTable.MfgTime -eq $null) -or ($IOMTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($IOMTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $IOMTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$IOMTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$IOMTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$IOMTable.Serial[$DoLoop-1]
if ($IOMTable.MfgTime.Count -ne 0)
{
if (($IOMTable.MfgTime[$DoLoop-1] -eq "") -or ($IOMTable.MfgTime[$DoLoop-1] -eq $null) -or ($IOMTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($IOMTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $IOMLoop)
}
#Writing FEX information to Excel
if ($FEXLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing FEX information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'FEX(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($FEXLoop -eq 1)
{
$DNFull = $FEXTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$FEXTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$FEXTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$FEXTable.Serial
if (($FEXTable.MfgTime -eq "") -or ($FEXTable.MfgTime -eq $null) -or ($FEXTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($FEXTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $FEXTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$FEXTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$FEXTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$FEXTable.Serial[$DoLoop-1]
if ($FEXTable.MfgTime.Count -ne 0)
{
if (($FEXTable.MfgTime[$DoLoop-1] -eq "") -or ($FEXTable.MfgTime[$DoLoop-1] -eq $null) -or ($FEXTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($FEXTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $FEXLoop)
}
#Writing Blade Server information to Excel
if ($BladeLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing Blade Server information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'Blade Server(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($BladeLoop -eq 1)
{
$DNFull = $BladeTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$SPFull = $BladeTable.ServiceProfile -match "/ls-(?<content2>.*)"
$SP = $matches['content2']
if ($SP -eq $null)
{
$SP = "<<UNASSOCIATED>>"
}
$Worksheet.Cells.Item($Loop+1,2) = "'"+$BladeTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$SP
$Worksheet.Cells.item($Loop+1,5) = "'"+$BladeTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$BladeTable.Serial
if (($BladeTable.MfgTime -eq "") -or ($BladeTable.MfgTime -eq $null) -or ($BladeTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($BladeTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $BladeTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$SPFull = $BladeTable.ServiceProfile[$DoLoop-1] -match "/ls-(?<content2>.*)"
$SP = $matches['content2']
if ($SP -eq $null)
{
$SP = "<<UNASSOCIATED>>"
}
$Worksheet.Cells.Item($Loop+1,2) = "'"+$BladeTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$SP
$Worksheet.Cells.item($Loop+1,5) = "'"+$BladeTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$BladeTable.Serial[$DoLoop-1]
if ($BladeTable.MfgTime.Count -ne 0)
{
if (($BladeTable.MfgTime[$DoLoop-1] -eq "") -or ($BladeTable.MfgTime[$DoLoop-1] -eq $null) -or ($BladeTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($BladeTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $BladeLoop)
}
#Writing Rack Server information to Excel
if ($RackLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing Rack Server information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'Rack Server(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($RackLoop -eq 1)
{
$DNFull = $RackTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$SPFull = $RackTable.ServiceProfile -match "/ls-(?<content2>.*)"
$SP = $matches['content2']
if ($SP -eq $null)
{
$SP = "<<UNASSOCIATED>>"
}
$Worksheet.Cells.Item($Loop+1,2) = "'"+$RackTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$SP
$Worksheet.Cells.item($Loop+1,5) = "'"+$RackTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$RackTable.Serial
if (($RackTable.MfgTime -eq "") -or ($RackTable.MfgTime -eq $null) -or ($RackTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($RackTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $RackTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$SPFull = $RackTable.ServiceProfile[$DoLoop-1] -match "/ls-(?<content2>.*)"
$SP = $matches['content2']
if ($SP -eq $null)
{
$SP = "<<UNASSOCIATED>>"
}
$Worksheet.Cells.Item($Loop+1,2) = "'"+$RackTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$SP
$Worksheet.Cells.item($Loop+1,5) = "'"+$RackTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$RackTable.Serial[$DoLoop-1]
if ($RackTable.MfgTime.Count -ne 0)
{
if (($RackTable.MfgTime[$DoLoop-1] -eq "") -or ($RackTable.MfgTime[$DoLoop-1] -eq $null) -or ($RackTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($RackTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $RackLoop)
}
#Writing Adapter information to Excel
if ($AdapterLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing Adapter information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'Adapter(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($AdapterLoop -eq 1)
{
$DNFull = $AdapterTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$AdapterTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$AdapterTable.ServiceProfile
$Worksheet.Cells.item($Loop+1,5) = "'"+$AdapterTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$AdapterTable.Serial
if (($AdapterTable.MfgTime -eq "") -or ($AdapterTable.MfgTime -eq $null) -or ($AdapterTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($AdapterTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $AdapterTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$AdapterTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$AdapterTable.ServiceProfile[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,5) = "'"+$AdapterTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$AdapterTable.Serial[$DoLoop-1]
if ($AdapterTable.MfgTime.Count -ne 0)
{
if (($AdapterTable.MfgTime[$DoLoop-1] -eq "") -or ($AdapterTable.MfgTime[$DoLoop-1] -eq $null) -or ($AdapterTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($AdapterTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $AdapterLoop)
}
#Writing Adapter Expansion information to Excel
if ($AdapterExpansionLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing Adapter Expansion information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'Adapter Expansion(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($AdapterLoop -eq 1)
{
$DNFull = $AdapterExpansionTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$AdapterExpansionTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$AdapterExpansionTable.ServiceProfile
$Worksheet.Cells.item($Loop+1,5) = "'"+$AdapterExpansionTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$AdapterExpansionTable.Serial
if (($AdapterExpansionTable.MfgTime -eq "") -or ($AdapterExpansionTable.MfgTime -eq $null) -or ($AdapterExpansionTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($AdapterExpansionTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $AdapterExpansionTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$AdapterExpansionTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$AdapterExpansionTable.ServiceProfile[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,5) = "'"+$AdapterExpansionTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$AdapterExpansionTable.Serial[$DoLoop-1]
if ($AdapterExpansionTable.MfgTime.Count -ne 0)
{
if (($AdapterExpansionTable.MfgTime[$DoLoop-1] -eq "") -or ($AdapterExpansionTable.MfgTime[$DoLoop-1] -eq $null) -or ($AdapterExpansionTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($AdapterExpansionTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $AdapterExpansionLoop)
}
#Writing DIMM information to Excel
if ($DIMMsLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing DIMM information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'DIMM(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($DIMMsLoop -eq 1)
{
$DNFull = $DIMMsTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$DIMMsTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$DIMMsTable.ServiceProfile
$Worksheet.Cells.item($Loop+1,5) = "'"+$DIMMsTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$DIMMsTable.Serial
if (($DIMMsTable.MfgTime -eq "") -or ($DIMMsTable.MfgTime -eq $null) -or ($DIMMsTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($DIMMsTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $DIMMsTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$DIMMsTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$DIMMsTable.ServiceProfile[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,5) = "'"+$DIMMsTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$DIMMsTable.Serial[$DoLoop-1]
if ($DIMMsTable.MfgTime.Count -ne 0)
{
if (($DIMMsTable.MfgTime[$DoLoop-1] -eq "") -or ($DIMMsTable.MfgTime[$DoLoop-1] -eq $null) -or ($DIMMsTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($DIMMsTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $DIMMsLoop)
}
#Writing Storage Controller information to Excel
if ($StorageControllerLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing Storage Controller information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'Storage Controller(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($StorageControllerLoop -eq 1)
{
$DNFull = $StorageControllerTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$StorageControllerTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$StorageControllerTable.ServiceProfile
$Worksheet.Cells.item($Loop+1,5) = "'"+$StorageControllerTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$StorageControllerTable.Serial
if (($StorageControllerTable.MfgTime -eq "") -or ($StorageControllerTable.MfgTime -eq $null) -or ($StorageControllerTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($StorageControllerTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $StorageControllerTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$StorageControllerTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$StorageControllerTable.ServiceProfile[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,5) = "'"+$StorageControllerTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$StorageControllerTable.Serial[$DoLoop-1]
if ($StorageControllerTable.MfgTime.Count -ne 0)
{
if (($StorageControllerTable.MfgTime[$DoLoop-1] -eq "") -or ($StorageControllerTable.MfgTime[$DoLoop-1] -eq $null) -or ($StorageControllerTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($StorageControllerTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $StorageControllerLoop)
}
#Writing Local Disk information to Excel
if ($StorageLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing Local Disk information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'Local Disk(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($StorageLoop -eq 1)
{
$DNFull = $StorageTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$StorageTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$StorageTable.ServiceProfile
$Worksheet.Cells.item($Loop+1,5) = "'"+$StorageTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$StorageTable.Serial
if (($StorageTable.MfgTime -eq "") -or ($StorageTable.MfgTime -eq $null) -or ($StorageTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($StorageTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $StorageTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$StorageTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$StorageTable.ServiceProfile[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,5) = "'"+$StorageTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$StorageTable.Serial[$DoLoop-1]
if ($StorageTable.MfgTime.Count -ne 0)
{
if (($StorageTable.MfgTime[$DoLoop-1] -eq "") -or ($StorageTable.MfgTime[$DoLoop-1] -eq $null) -or ($StorageTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($StorageTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $StorageLoop)
}
#Writing Fan information to Excel
if ($FanLoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing Fan information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'Fan(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($FanLoop -eq 1)
{
$DNFull = $FanTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$FanTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$FanTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$FanTable.Serial
if (($FanTable.MfgTime -eq "") -or ($FanTable.MfgTime -eq $null) -or ($FanTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($FanTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $FanTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$FanTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'N/A" #Service Profile
$Worksheet.Cells.item($Loop+1,5) = "'"+$FanTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$FanTable.Serial[$DoLoop-1]
if ($FanTable.MfgTime.Count -ne 0)
{
if (($FanTable.MfgTime[$DoLoop-1] -eq "") -or ($FanTable.MfgTime[$DoLoop-1] -eq $null) -or ($FanTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($FanTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $FanLoop)
}
#Writing PSU information to Excel
if ($PSULoop -ne 0)
{
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Writing Power Supply information to Excel" -NoNewline
$DoLoop = 1
$Loop += 1
$Worksheet.Cells.item($Loop+1,1) = "'PSU(s)"
do
{
Write-Host -ForegroundColor DarkBlue "." -NoNewline
if ($PSULoop -eq 1)
{
$DNFull = $PSUTable.DN -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$PSUTable.UCS
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$PSUTable.ServiceProfile
$Worksheet.Cells.item($Loop+1,5) = "'"+$PSUTable.Model
$Worksheet.Cells.item($Loop+1,6) = "'"+$PSUTable.Serial
if (($PSUTable.MfgTime -eq "") -or ($PSUTable.MfgTime -eq $null) -or ($PSUTable.MfgTime -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($PSUTable.MfgTime -replace "T", " ")
}
$Loop += 1
$DoLoop += 1
}
else
{
$DNFull = $PSUTable.DN[$DoLoop-1] -match "/(?<content>.*)"
$DN = $matches['content']
$Worksheet.Cells.Item($Loop+1,2) = "'"+$PSUTable.UCS[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,3) = "'"+$DN
$Worksheet.Cells.item($Loop+1,4) = "'"+$PSUTable.ServiceProfile[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,5) = "'"+$PSUTable.Model[$DoLoop-1]
$Worksheet.Cells.item($Loop+1,6) = "'"+$PSUTable.Serial[$DoLoop-1]
if ($PSUTable.MfgTime.Count -ne 0)
{
if (($PSUTable.MfgTime[$DoLoop-1] -eq "") -or ($PSUTable.MfgTime[$DoLoop-1] -eq $null) -or ($PSUTable.MfgTime[$DoLoop-1] -eq "not-applicable"))
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+($PSUTable.MfgTime[$DoLoop-1] -replace "T", " ")
}
}
else
{
$Worksheet.Cells.item($Loop+1,7) = "'"+"N/A"
}
$Loop += 1
$DoLoop += 1
}
}
while ($DoLoop -le $PSULoop)
}
#Save the Excel file
Write-Host ""
Write-Host ""
[string]$ConnectedUCS = ($FIs | where {$_.Id -eq "A"}).ucs
if ($ConnectedUCS.Length -ge 232)
{
$UCSList = $ConnectedUCS.substring(0,220)
}
else
{
$UCSList = $ConnectedUCS
}
$file = $PSScriptRoot + "\UCS Serial Numbers for "+$UCSList+".xlsx"
Write-Host -ForegroundColor DarkBlue "The Excel file will be created as:" -NoNewline
Write-Host -ForegroundColor White -BackgroundColor DarkBlue $file
Write-Host -ForegroundColor DarkBlue " Saving Excel File...Please wait..."
$Workbook.SaveAs($file)
Write-Host -ForegroundColor DarkGreen " Complete"
#Close the Excel file
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Closing Excel Spreadsheet"
$Workbook.Close()
#Exit Excel
Write-Host ""
Write-Host -ForegroundColor DarkBlue "Exiting Excel"
$Excel.Quit()
#Exit the Script
Write-Host ""
Write-Host -ForegroundColor White -BackgroundColor DarkBlue "Script Complete"
Disconnect-Ucs
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment