PowerCLI: Determine Deployment Times

Surprisingly it can be difficult to track exactly how long a VM has taken to deploy. So, I dug into the events part of powercli and came up with a way to calculate deployment times.

Basically the script is looking for the VMDeingDeployedEvent start time and then the VMDeployedEvent start time. We then take the difference of the 2 and print that out. It also matches up these 2 events based on a “chainid” that makes sure they match up.

If you have a large environment you might have to do many events to go back even a week. In my current environment that is of decent size about 500,000 events went back about a month.

The output is Name, Date, Minutes, Seconds for deploy and shows the oldest to newest, but you can sort it however you like.

Here is the script:

<#
.SYNOPSIS
   <A brief description of the script>
.DESCRIPTION
   <A detailed description of the script>
.PARAMETER <paramName>
   <Description of script parameter>
.EXAMPLE
   <An example of using the script>
#>

$samples = Read-Host "Enter Number of Samples to go back"

$events = Get-VIEvent -maxsamples $samples | where {$_.Gettype().Name -eq "VmBeingDeployedEvent" -or $_.gettype().name -eq "VmDeployedEvent"}
$VMDeployReport = @()
$events | where {$_.Gettype().Name -eq "VmBeingDeployedEvent"} | % {
        $row = "" | Select Name, Date, Minutes, Seconds
        $chainidkey = $_.chainid
        $VmName = ($_.FullFormattedMessage).split('')[1]
        $deployed = $events | where {$_.gettype().name -eq "VmDeployedEvent" -and $_.Chainid -eq $chainidkey}
        $StartTime = $_.createdtime
        #$date = $deployed.CreatedTime.ToString().split('')[0]
        $endtime = $deployed.createdtime
        $time = New-TimeSpan -start $starttime -end $endtime
        $row.Name = $VmName
        $row.date = $EndTime
        $row.Minutes = $time.Minutes
        $row.Seconds = $time.Seconds
        $VMDeployReport += $row
        }
        $VMDeployReport 

Interview with VMware’s Founder

I thought this was a very good interview so I figured I’d share!

Interview with Vmware Founder

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:

Capture

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}}
    }
    else 
    {
        Write-host "Failed to find" $_.hostname 
    }
} | Export-Csv -NoTypeInformation vm_list.csv

VMware Product Walkthrough Videos

I recently stumbled across an excellent page from VMware that I had never seen before.  I figure others would enjoy this page as much as I do.  On the page it has a collection of videos provided for many of their offerings to get you up to speed!  It’s a nice little nugget of information that I hope others will enjoy.

https://featurewalkthrough.vmware.com/

vmwarefeatures

VSAN does not see all disks due to previous partitions

During my testing out of VSAN I ran into an issue where VSAN was unable to see all of the disks in the box.  This can occur if there was something loaded on those disks.  The way around this is you need to SSH into the server and list the disks to see if there are partitions.

Step 1: List the disks and look for parititions.  Below you can see there are 2 partitions on this disk.

ls /dev/disks/naa*
/dev/disks/naa.600605b00896b6e01acf437ab22efc8e /dev/disks/naa.600605b00896b6e01acf4384b2c815fa
/dev/disks/naa.600605b00896b6e01acf437ab22efc8e:1 /dev/disks/naa.600605b00896b6e01acf4384b2c815fa:1
/dev/disks/naa.600605b00896b6e01acf437ab22efc8e:2 /dev/disks/naa.600605b00896b6e01acf4384b2c815fa:2

Step 2:  Delete all the partitions

partedUtil delete /dev/disks/naa.600605b00896b6e01acf437ab22efc8e 1

After this you may need to disable and re-enable the VSAN check box to see the new disks.

Blogging this year….A challenge

I haven’t had too many updates this year, but I am not quitting on the blog.  There has just been a large amount of work internally where I work.

There are many initiatives I am leading up which should provide some excellent blogging material once I have more information.  We are currently testing out automation suites and hyperconverged infrastructures.

I hope to begin blogging on my experiences with these as soon as I can find more time.