VMware Cloud Community
vbhost
Contributor
Contributor

vMotion history for a group of virtual machines

Hello Folks

I have been using Events - Part 8 - vMotion history - LucD notes to retrieve the vmotion history, but it works only if I don't filter any group servers. It works for the entire DC.

If I use it just for one server by amending the below lines, it works perfectly fine.

Lines 9-13

$vmName = 'MyVMName'

# Get the guest for which we want the report

$vmHash = @{}

Get-Datacenter -Name "MyDC" | Get-VM -Name $vmName| %{

$vmHash[$_.Name] = $_.Host

}

AND Lines 41-52

"VmBeingHotMigratedEvent" {

if($task.EntityName -eq $vmName){

$migrations += New-Object PSObject -Property @{

VMname = $task.EntityName

Source = $event.Host.Name

Destination = $event.DestHost.Name

Start = $task.StartTime

Finish = $task.CompleteTime

Result = $task.State

User = $task.Reason.UserName

DRS = &{if($task.DescriptionId -like "Drm.*"){$true}else{$false}}

}

}

}

But if I want it only for specific servers and take the input from a test file, like below

$Computers= Get-Content -Path ("C:\List.txt")

foreach ($vmName in $Computers) {

$vmHash = @{}

Get-Datacenter -Name "E11" | Get-VM -Name $vmName| %{

  $vmHash[$_.Name] = $_.Host

}

And, I end the "for loop" no matter where, it doesn't give me the full vmotion history. It will only extract the first time stamp and the last time stamp vmotion history of a particular server. It will omit everything else out. If I end the 'for loop ' n the below section, same thing happens, if I end it before the below section, only the last VM history comes, the other are overwritten, even if I use -append parameter.

# Add remaining guests to report

$vmHash.GetEnumerator() | %{

  $row = New-Object PSObject

  Add-Member -InputObject $row -Name VM -Value $_.Name -MemberType NoteProperty

  Add-Member -InputObject $row -Name Time1 -Value $start -MemberType NoteProperty

  Add-Member -InputObject $row -Name Host1 -Value $_.Value -MemberType NoteProperty

  Add-Member -InputObject $row -Name DRS1 -Value $false -MemberType NoteProperty

  $report += $row

}

}

Can someone please help me with how to filter group of VM's with complete vmotion history, because I can see that the VM has vmotioned more number of times than what is the script is outputting, via VI tasks and events, and even if use the script just for one VM.

Tags (1)
0 Kudos
1 Reply
LucD
Leadership
Leadership

The easiest way is to filter the results, and only select the servers you are interested in.

The reason it is hard to do this filtering earlier is the way the TaskCollector is set up.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos