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:

   <A brief description of the script>
   <A detailed description of the script>
.PARAMETER <paramName>
   <Description of script parameter>
   <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

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: