try looking anyone can share powershell to pull report cluster vmotion report and then export out to exle file. thanks
Thread reported so moderators know it should be moved to the PowerCLI area.
after run script,
Get-MotionHistory -Entity (Get-VM VM*) -Days 1 |Export-Csv C:\motion-report1.csv -NoTypeINformation -UseCultureand
then run this script get an error
That error seems to say that Get-VM VM* didn't return anything.
Have a look at Get the vMotion/svMotion history
try the script but when it export it not show anything relate to DRS, is this script working with vmware ver 6.7. thanks
I changed line 163 to
$eventTypes = "DrsVmMigratedEvent", "VmMigratedEvent", "VmRelocatedEvent"
and then called like this
Get-Cluster -Name cluster | Get-MotionHistory -Days 1 -Recurse
and that returned all vMotions and svMotions from the last day.
this is the scrip i try, it only up to 101 line. please assist thanks
$start = (Get-Date).AddHours(-$hours)$tasknumber = 999 # Windowsize for task collector$eventnumber = 100 # Windowsize for event collector$tgtTaskDescriptions = "VirtualMachine.migrate","Drm.ExecuteVMotionLRO"$migrations = @()$report = @()# Get the guest for which we want the report$vmHash = @{}Get-Cluster -Name "P1" | Get-VM | %{$vmHash[$_.Name] = $_.Host}# Retrieve the vMotion tasks and the corresponding events$taskMgr = Get-View TaskManager$eventMgr = Get-View eventManager$tFilter = New-Object VMware.Vim.TaskFilterSpec$tFilter.Time = New-Object VMware.Vim.TaskFilterSpecByTime$tFilter.Time.beginTime = $start$tFilter.Time.timeType = "startedTime"$tCollector = Get-View ($taskMgr.CreateCollectorForTasks($tFilter))$dummy = $tCollector.RewindCollector$tasks = $tCollector.ReadNextTasks($tasknumber)while($tasks){$tasks | where {$tgtTaskDescriptions -contains $_.DescriptionId} | % {$task = $_$eFilter = New-Object VMware.Vim.EventFilterSpec$eFilter.eventChainId = $task.EventChainId$eCollector = Get-View ($eventMgr.CreateCollectorForEvents($eFilter))$events = $eCollector.ReadNextEvents($eventnumber)while($events){$events | % {$event = $_switch($event.GetType().Name){"VmBeingHotMigratedEvent" {$migrations += New-Object PSObject -Property @{VMname = $task.EntityNameSource = $event.Host.NameDestination = $event.DestHost.NameStart = $task.StartTimeFinish = $task.CompleteTimeResult = $task.StateUser = $task.Reason.UserNameDRS = &{if($task.DescriptionId -like "Drm.*"){$true}else{$false}}}}Default {}}}$events = $eCollector.ReadNextEvents($eventnumber)}$ecollection = $eCollector.ReadNextEvents($eventnumber)# By default 32 event collectors are allowed. Destroy this event collector.$eCollector.DestroyCollector()}$tasks = $tCollector.ReadNextTasks($tasknumber)}# By default 32 task collectors are allowed. Destroy this task collector.$tCollector.DestroyCollector()# Handle the guests that have been vMotioned$grouped = $migrations | Group-Object -Property VMname$grouped | Sort-Object -Property Count -Descending | where{$vmHash.ContainsKey($_.Name)} | %{$i = 1$row = New-Object PSObjectAdd-Member -InputObject $row -Name VM -Value $_.Name -MemberType NoteProperty$_.Group | Sort-Object -Property Finish | %{# The original location of the guestif($i -eq 1){Add-Member -InputObject $row -Name ("Time" + $i) -Value $start -MemberType NotePropertyAdd-Member -InputObject $row -Name ("Host" + $i) -Value $_.Source -MemberType NoteProperty$i++}# All the vMotion destinationsAdd-Member -InputObject $row -Name ("Time" + $i) -Value $_.Finish -MemberType NotePropertyAdd-Member -InputObject $row -Name ("Host" + $i) -Value $_.Destination -MemberType NotePropertyAdd-Member -InputObject $row -Name ("DRS" + $i) -Value $_.DRS -MemberType NotePropertyAdd-Member -InputObject $row -Name ("User" + $i) -Value $_.User -MemberType NoteProperty$i++}$report += $row$vmHash.Remove($_.Name)}# Add remaining guests to report$vmHash.GetEnumerator() | %{$row = New-Object PSObjectAdd-Member -InputObject $row -Name VM -Value $_.Name -MemberType NotePropertyAdd-Member -InputObject $row -Name Time1 -Value $start -MemberType NotePropertyAdd-Member -InputObject $row -Name Host1 -Value $_.Value -MemberType NotePropertyAdd-Member -InputObject $row -Name DRS1 -Value $false -MemberType NoteProperty$report += $row}$report | Export-Csv "C:\tmp\vMotion-history.csv" -NoTypeInformation -UseCulture
That is not the script I linked to.Where does this come from?
it from your website...can you please share again thanks
The link is in my 1st reply in this thread.
thanks it working now, how do i export all info into xls file.
If a CSV is sufficient you can pipe the result to an Export-Csv cmdet.If you want an XLSX file, you will have to install the ImportExcel module, and pipe the result to the Export-Excel cmdlet.