Powercli and UCS: Report which FI/blade type your hosts are contained in.

In smaller environments this script may not be that great, but what if you have 20 pairs of Fabric Interconnects and 1000 hosts?  Don’t have a good CMDB or are trying to track down which FI your hosts are in to troubleshoot?

Expanding on my last post we will create a new VI property and also dig into the CDP (Cisco Discovery Protocol) to determin which FI your hosts is connected to along with what VCenter.

As part of the script you will need to connect to any and all VCenters with Powercli then run the script below.  It will output: hostname, cluster, version, vcenter build, blade type, and FI name.

New-VIProperty -Name vCenterServer -ObjectType VMHost -Value {$Args[0].Uid.Split(“:”)[0].Split(“@”)[1]} -Force | Out-Null
$date = (get-date).tostring('M-d-y')
Get-VMHost | %{
        $vmhostview = Get-View $_
        $networksystem = Get-view $vmhostview.ConfigManager.NetworkSystem
        $FI = $networksystem.QueryNetworkHint($networksystem.pnic).connectedSwitchPort.systemname[1].split("-")[0] 
        $_ | select Name,Version,Build,Parent,Model,@{Name="Vcenter";Expression={($_ | select vcenterserver).vcenterserver}},@{Name="FI";Expression={$FI}}
        } | Export-Csv -NoTypeInformation master_hostlist-$date.csv

Output will look as follows:


PowerCLI: Host and VM location script across many Vcenters

If a company has a very large environment with many vcenters it sometimes can be difficult to track down where a host my be located.  Then let’s say you need to know what VM’s and what hosts are running on top of it? For this script you do need a list of hosts that you want to find.  If you want to just find out all the information you could modify the script to make the hostlist to just be get-vmhost instead of from a file.

I wrote a small script that once connected to all your vcenters, you can pass a csv with a list of hostnames and it will pull the VM’s, their host, and which VC it is in back out into a CSV.  In the script we are using the VIProperty cmdlet which lets you make your own property for objects in vmware.

The CSV will need to have the header “hostname” and then the FQDN of the hosts below it.

#Ready host file name in
$hostlist = Read-Host "Enter server list name"
$hostlist = Import-Csv $hostlist

# Create Vcenter Location Property
New-VIProperty -Name vCenterServer -ObjectType VMHost -Value {$Args[0].Uid.Split(“:”)[0].Split(“@”)[1]} -Force | Out-Null

#Loop through the hostlist and create spreadsheet.  Write for any hosts that aren't found.
$hostlist | %{
    Write-Host "Starting" $_.hostname
    if (Get-VMHost $_.hostname -ErrorAction SilentlyContinue ) { 
    $vmhost = get-vmhost $_.hostname
    $vmhost| get-vm | select Name,VMHost,@{Name="Vcenter";Expression={($vmhost | select vcenterserver).vcenterserver}}
        Write-host "Failed to find" $_.hostname 
} | Export-Csv -NoTypeInformation vm_list.csv

VMware 5.5 U1 Release Announcement

Big announcement yesterday for the release of U1 for 5.5 in case you missed it!  This includes PowerCLI 5.5 R2 (includes new SRM cmdlets!!!), ESXi 5.5.1, Vcenter 5.5.1, SRM 5.5.1.  There appears to be a large number of bug fixes so I would recommend going to it as soon as you can if you are already on 5.5.  I have the upgrade screenshots coming for the 5.5 upgrade which should be the same as the U1 upgrade.  I am working on  the 5 part custom install series for Vcenter/SRM 5.5 postings as we speak so hopefully will have them out shortly.

VSAN is finally out of beta and now to GA. It is good to note that it is NOT bundled in with any version of the Vsphere license and is a separate purchased product.

VMware Virtual SAN Virtual SAN 5.5 is a new hypervisor-converged storage tier that extends the vSphere Hypervisor to pool server-side magnetic disks (HDDs) and solid-state drives (SSDs). By clustering server-side HDDs and SSDs, Virtual SAN creates a distributed shared datastore designed and optimized for virtual environments. Virtual SAN is a standalone product that is sold separate from vSphere and requires its own license key

As far as the announcement here are the links to the release notes, be sure to read through all the bug fixes and see if any apply to your environment.

ESXi 5.5 U1 Release Notes: https://www.vmware.com/support/vsphere5/doc/vsphere-esxi-55u1-release-notes.html

Vcenter 5.5 U1 Release Notes: https://www.vmware.com/support/vsphere5/doc/vsphere-vcenter-server-55u1-release-notes.html

SRM 5.5.1 Release Notes: https://www.vmware.com/support/srm/srm-releasenotes-5-5-1.html

PowerCLI 5.5 R2 Release Notes: https://www.vmware.com/support/developer/PowerCLI/PowerCLI55R2/powercli55r2-releasenotes.html

Migrate Host and Guests VDS to SS using Powercli 5.5

Here is the follow up to my previous posting Migrate Host and Guests from SS to VDS using Powercli 5.5

Requirements for script: Host with 2 physical interfaces, VSwitch must already be setup with VM portgroups with the same names as you have on the VDS. If you have more than 2 physical nics you can modify the script below with the remove and add adapter commands for all your NICS. There are plenty of scripts out there to copy the VDS to Vswitch port groups if that task needs to be done.

The script below will allow you to migrate your host and guests back to Standard Switch! There was one issue I found with the Add-VirtualSwitchPhysicalNetworkAdapter cmdlet when migrating VMkernel ports. Instead of being able to name the portgroup as it migrates, it takes the default name of VMkernel and VMkernel2 for Management and Vmotion respectively. Be sure to also hardcode the Vlan ID in the Set-VirtualPortGroup rename cmdlet below for your tags.

So, after migrating them we run a separate command to have those Vmkernel ports renamed. You can modify the script to name them how you would like. I named them Management Network and VMotion.

The script will prompt you for the host you want to migrate, the VDswitch name you want to migrate off of, and the Vswitch you want to migrate to.

It will move 1 interface over with the 2 Vmkernel ports VMotion/Management, loop through all interfaces of the VM’s and set the portgroups to the matching standard switch groups, migrate 2nd interface, and remove from VDS.

$VMHost = Read-Host "Enter Hostname to Migrate"
$VDSwitch = Read-Host "Enter VDSwitch Name"
$VSwitch = Read-Host "Enter Standard VSwitch Name"

#Get VMhost object data
$VMHostobj = Get-VMHost $VMHost

#create vmlist
$vmlist = $VMHostobj | Get-VM

#Remove 1 uplink and migrate to standard
$VMhostObj | Get-VMHostNetworkAdapter -Physical -Name "vmnic1" | Remove-VDSwitchPhysicalNetworkAdapter -Confirm:$false
$VSwitch = $VMhostObj | Get-VirtualSwitch -Name $VSwitch

#Get physical adapter to move
$vmhostadapter = $VMhostObj | Get-VMHostNetworkAdapter -Physical -Name vmnic1 

# Get 

# Get Vmotion and Management Virtual Adaptesr
$vmk0 = Get-VMHostNetworkAdapter -vmhost $vmhostobj -name vmk0
$vmk1 = Get-VMHostNetworkAdapter -vmhost $vmhostobj -name vmk1

# Add 1 physical adapter 
Add-VirtualSwitchPhysicalNetworkAdapter -VirtualSwitch $VSwitch -VMHostVirtualNic $vmk0,$vmk1 -VMHostPhysicalNic $vmhostadapter -Confirm:$false

#Rename the VMkernel ports to Vmotion and Management
$VMhostObj | Get-VirtualPortGroup -Name "VMkernel" | Set-VirtualPortGroup -VLanId 20 -Name "Management Network"
$VMhostObj | Get-VirtualPortGroup -Name "VMkernel2" | Set-VirtualPortGroup -VLanId 10 -Name "VMotion"

# Loop through guests and set their networks.
foreach($vm in $vmlist){
    Get-NetworkAdapter $vm | %{
    Write-Host "Setting adapter" $_.NetworkName on $vm
    $_ | Set-NetworkAdapter -PortGroup (Get-VirtualPortGroup -VMhost  $VMHost -Standard -Name $_.NetworkName) -Confirm:$false

#Swing Second Physical Interface Over
$VMhostObj | Get-VMHostNetworkAdapter -Physical -Name "vmnic0" | Remove-VDSwitchPhysicalNetworkAdapter -Confirm:$false

$vmhostadapter = $VMhostObj | Get-VMHostNetworkAdapter -Physical -Name vmnic0
Add-VirtualSwitchPhysicalNetworkAdapter -VirtualSwitch $VSwitch -VMHostPhysicalNic $vmhostadapter -Confirm:$false

#Remove from VDS
Get-VDSwitch $VDSwitch | Remove-VDSwitchVMHost -VMHost $VMhostObj -Confirm:$false

Migrate Host and Guests from SS to VDS using Powercli 5.5

I have a pretty popular older post to migrate off of a VDS to a standard switch using some of the API calls, but this has now been made easier with Powercli 5.5. The addition and update of a few cmdlets around standard switch and VDS migrations are now here!

Requirements: Powercli 5.5

These are:




The script below will show how to move a single host and all of it’s guests to a VDS for a host with 2 physical uplinks.  It can be modified if you have more than 2 uplinks.  You will need to be sure to modify the commands to your environment like the line to migrate vmk0 and vmk1 make sure they line up with what you named your management and Vmotion port group!

In the next post, I will document how to go in the other direction to get off of the VDS to the Standard Switch!

Here is the script, feel free to use and distribute! This script assumes you already have a VDS setup with Virtual Machine portgroups with the same name and VLAN ID’s as on the standard switch already configured and setup. This allows the for loop in the script to loop through each interface and set the network label.

$VMHost = Read-Host "Enter Hostname to Migrate"
$VDSwitch = Read-Host "Enter VDSwitch Name"

#Get VMhost object data
$VMHostobj = Get-VMHost $VMHost

#create vmlist
$vmlist = $VMHostobj | Get-VM

#Add to new DVSwitch and swing leg over
$VMhostObj | Get-VMHostNetworkAdapter -Physical -Name "vmnic1" | Remove-VirtualSwitchPhysicalNetworkAdapter -Confirm:$false
$VDSwitch = Get-VDSwitch $VDSwitch
$VDSwitch |  Add-VDSwitchVMHost -VMHost $VMHost -Confirm:$false

#Get physical adapter to move
$vmhostadapter = $VMhostObj | Get-VMHostNetworkAdapter -Physical -Name vmnic1 

# Get Vmotion and Management Virtual Adaptesr
$vmk0 = Get-VMHostNetworkAdapter -vmhost $vmhostobj -name vmk0
$vmk1 = Get-VMHostNetworkAdapter -vmhost $vmhostobj -name vmk1

# Add 1 physical adapter 
Add-VDSwitchPhysicalNetworkAdapter -DistributedSwitch $VDSwitch -VirtualNicPortgroup "Management","Vmotion" -VMHostVirtualNic $vmk0,$vmk1 -VMHostPhysicalNic $vmhostadapter -Confirm:$false

# Loop through guests and set their networks.
foreach($vm in $vmlist){
    Get-NetworkAdapter $vm | %{
    Write-Host "Setting adapter" $_.NetworkName on $vm
    $_ | Set-NetworkAdapter -PortGroup (Get-VDPortGroup -Name $_.NetworkName -VDSwitch $VDSwitch) -Confirm:$false

#Swing Second Physical Interface Over
$VMhostObj | Get-VMHostNetworkAdapter -Physical -Name "vmnic0" | Remove-VirtualSwitchPhysicalNetworkAdapter -Confirm:$false

$vmhostadapter = $VMhostObj | Get-VMHostNetworkAdapter -Physical -Name vmnic0
$VDSwitch | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostadapter -Confirm:$false

ESXi Kickstart while completely ignoring remote disks

Ever worried that your kickstart install might accidentally overwrite your SAN luns?  There are a couple of options around this, but I prefer the option  where you don’t have to involve your SAN team. Now, this won’t work if you are booting from SAN as you will need your HBA driver. I will be testing how to and ignore any non boot luns on a boot from SAN scenario hopefully in the near future.

This article assumes you already are familiar with the kickstart process.

Option 1: For all hosts you want to run a kickstart installation on, ask your SAN team to unmask the luns to this host and then remask when the host is finished upgrading. Or have cables unplugged and plugged back in.

Option 2: Remove your HBA driver from your image using PowerCli ImageBuilder and then reinstall driver using your %firstboot script and a web server.

In order to do Option 2, you will need to have the following components downloaded:
1. Powercli (preferably the latest version)
2. Offline Bundle for the ESXi installation from Vmware’s downloads page. (will be in .zip format). This is where you will get the vib to reinstall either during kickstart or after install.

Let’s get started!

Part I – Create ISO with no FC driver using PowerCLI Image Builder

1. You can determine what your HBA driver is by SSH’ing into one of your current hosts and running this command: esxcli storage core adapter list.

2. Now, we will be creating the new ISO that has the FC driver removed.
3. Login to an existing host and determine what the driver is for your HBA. In our case it is the lpfc driver.
4. Open Powercli and cd to the working directory.
5. Add the online software depot from Vmware which will contain the ESXi Images: Add-EsxSoftwareDepot https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xmladd-depot
6. Get a list of Images from the depot: Get-ESxImageProfile |Select Name,CreationTime|Sort CreationTime.

7. Create a new profile to work on: New-EsxImageProfile –CloneProfile ESXi-5.1.0-20130504001-standard –Name “Test”.

8. You can search for all the drivers in the image by doing Get-ESXSoftwarePackage. Search for the driver your HBA uses. Normally, this will be the scsi-lpfc driver.
9. You can then remove the driver: Remove-EsxSoftwarePackage –imageprofile Test –SoftwarePackage scsi-lpfc820.remove_fc
10. Now, export your new ISO without the FC driver: Export-ESXImageProfile –ImageProfile “test” –ExporttoIso .\No_HBA.iso


Part II – Make VIB available

1. Copy your ESXi offline bundle into the directory you want to work in. This includes the ESXi installation and the driver for your HBA.
2. Extract the fibre channel lpfc .vib from the offline bundle. It should be under the vib sub directory.
3. Place this .vib in an accessible web server either in IIS or apache so that your kickstart post install can reinstall the driver.

Part III – Reinstall FC driver during Kickstart

1. In your kickstart file, add this line to your %firstboot file to install the FC vib from your web server:
#Install FC driver
esxcli software vib install -v http://webserver/VMware_bootbank_scsi-lpfc820_8.2.3.1-127vmw.510.0.0.799733.vib
2. Boot to your new ISO with the HBA removed.
3. Run your normal kickstart install and you now no longer have to worry about accidentally overwriting a lun!

Migrate ESXi host and guests from 1000v / VDS to Standard Switch using Powercli

Migrate Host and Guests VDS to SS using Powercli 5.5

On occasion, there is a need to migrate an entire host or even cluster from the VDS to a standard switch. We happen to do this frequently for assorted operations like an upgrade or moving to another VDS. So, I wrote a script combining some of my previous posts to put it all together.

Below are the configuration and the steps we would follow for our environment.  You may need to tweak the scripts slightly depending on how many interfaces that you have.

Our Configuration:

1.  Hosts are on the 1000v

2.  We only have 2, 10 GB uplinks/vmnics.  These are Dell half height blades.

3. No standard switch currently configured, but Vswitch0 is present.

4.  Only 1 VMkernel portgroup for Vmotion and Management respectively.

5.  Portgroup names are labeled identically the same (required for the for loop to work properly.

Steps to migrate to the standard switch:
Read more of this post