Automated ESXi Cisco UCS Firmware Upgrade using Powertool

I have completed a script that will allow you to put a host into maintenance mode, verify service profile based on MAC address, and then change your firmware policy.

Requirements for the Script:
Cisco Powertool 1.x or later
Vmware Powercli 5.x or later
Maintenance Policy is User Ack
Ensure your VMNIC0 is matched up with your first Vnic template in order.

In line 34 you will need to modify the hardcoded VNIC to whatever you have named as your 1st PCI vnic on your Service Profile Template. This also assumes you have connected to UCS manager in a Powertool window.

Now for the script!

<#
.SYNOPSIS
   Upgrades Firmware on a UCS Vmware Host
.DESCRIPTION
   Script will put host in maintenance mode.  Verify the service profile in for the host by maching up MAC address to VMNIC0.  Apply firmware and acknowledge for reboot.  
.PARAMETER <paramName>
   <Description of script parameter>
.EXAMPLE
   <An example of using the script>
#>

# Add the VMware Snapin to the Powertools Window
Add-PSSnapin VMware.VimAutomation.Core
Set-powercliconfiguration -InvalidCertificateAction ignore -Confirm: $false

# Prompt for the Vcenter for you host, ESXi hostname, and Firmware package you want to use.
$vcenter = Read-Host "Enter Vcenter Name"
$vmhostname = Read-Host "Enter ESXi Hostname"
$fw = Read-Host "Enter Firmware Version"

# Connect to Vcenter
Connect-Viserver $vcenter
# Put Host into Maintenance Mode
Set-VMHost -VMHost $vmhostname -State "Maintenance" -confirm:$false

# Get Host Mac Address
$vmhost = Get-VMHost $vmhostname
$vmMacAddr = $VMhost.NetworkInfo.PhysicalNic | where { $_.name -ieq "vmnic0" }

# Shutdown VMhost
Stop-VMHost $vmhost -Confirm:$false

#Wait for ESXi host to completely shut down
while (Get-VMHost $vmhost | where {$_.ConnectionState -eq "Maintenance"}) {write-host "Waiting for $VMhost to Shutdown"; sleep 30}

#Get Service Profile that matches the MAC address
$SP = (Get-UcsServiceProfile | Get-UCSVnic -Name vNIC0_A | where {$_.addr -ieq $vmMacAddr.mac} | Get-UcsParent).Name

# Set Firmware Policy
Get-UcsServiceProfile -name $SP| Set-UcsServiceProfile -HostFwPolicyName $fw -Force

# Acknowledge the reboot
Get-UcsServiceProfile -Name "$SP" -LimitScope | Get-UcsLsmaintAck | Set-UcsLsmaintAck -AdminState "trigger-immediate" -Descr "" -PolicyOwner "local" -Scheduler "" -Force

# Wait for Server to be reconnected
while (Get-VMHost $vmhost | where {$_.ConnectionState -eq "Disconnected" -or $_.ConnectionState -eq "NotResponding"}) {write-host "Waiting for $VMhost to reconnect"; sleep 20}

# Take VMhost out of Maintenance Mode
Set-VMHost -VMHost $vmhost -State "Connected" -confirm:$false

# Disconnect from Vcenter
Disconnect-Viserver $vcenter -confirm:$false

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: