I need to know on which ESX host the VMs are located in the past.
I found a script who lists the current esx host where the VMs are located:
$vms = Get-VM | Sort Name
$vms | Select Name, @{N="VMHost";E={Get-VMHost -VM $_}}
How I can List the VMs history location? I.e. for the last 3 months?
Thanks in advance
Oliver
My mistake, the new line for the DRS property was not complete.
Attached the script with the PS v1 way of creating the object.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You will have to investigate the events for that.
Have a look at . It only lists DRS initiated vMotions but you can easily adapt this for other types of vMotions.
Is this waht you were looking for ?
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I've got some errors when running the script. What does this line of code do?
http://Reflection.Assembly::LoadWithPartialName("vmware.vim")
Thank in advance
Oliver
Use the attached script from that thread.
The forum SW has problems with square brackets.
You can in fact leave out that line, it was used to make sure the PowerCLI assemblies were loaded, but that is now done automatically.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
thank you for your answer. Unfortunately I´ve got additional errors if i run the script on the vSphere architecture:
Unable to find type [http://VMware.Vim.TaskHistoryCollector........
Regards
Oliver
Strange.
From where are you running the script ? From the PowerCLI prompt ? Or something else ?
And what version of PowerCLI do you have installed ? Use
Get-PowerCLIVersion
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Have a look at Events – Part 8 – vMotion history.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
great! I´ve run your script "Events – Part 8 – vMotion history" and got all the informations I need to know in a csv file. Thank you for supporting me.
But as I tryed to run it a second time the operation failed with this error:
A parameter cannot be found that matches parameter name 'Property'.
At :line:38 char:14
+ $events | % <<<< {
I don´t know whats going on.
I am using VMware vSphere PowerCLI 4.0 U1 build 208462
and the PowerGuiScript Editor 1.8.0.815
Regards
LarsOliver
LucD,
A second Question:
$report | Export-Csv "C:\vMotion-history.csv" -NoTypeInformation -UseCulture
What does the parameter -UseCulture do?
I cannot found a description using:
get-help Export-Csv -detailed
Thanks and Reggards
LarsOliver
The -UseCulture parameter is new in PowerShell v2.
The help says "Use the list separator for the current culture as the item delimiter. The default is a comma (,).".
I would strongly advice you to upgrade to PowerShell v2 (if you haven't done so already).
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Do you get that same error when you run the script a 2nd time from the PowerCLI prompt ?
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
thanks, now it works , great script !
But I,ve got only the following colums for my 445 VMs:
VM Time1 Host1 DRS1
The DRS1 Colum shows only FALSE entrys. It seems that no VM has moved in the last 30 hours. I will check this again with a longer time period at monday.
Thanks
LarsOliver
Or move 1 or 2 guests before you run the script.
Make sure that the guests selection (line 11-13) contains these VMs.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
thanks for your reply.
Same status as Friday. I moved one VM. The script detects the new esx, but do not show the esx, where the vm came from, in the table.
I´ve done a little modification to selected the cluster with this command:
Get-Cluster -name "mycluster" | Get-VM | %{
$vmHash[http://$_.Name|http://$_.Name] = $_.Host
}
The correct VMs are displayed in the table, but no movements. Independently if I set the $hours variable to 24, 240 or 750 (1 month). The Size of the csv doesn´t change, it is the same (6KB) and also the number of the VMs.
I wrote the messages into a log file and found the following message three times.
New-Object : A parameter cannot be found that matches parameter name 'Property'.
At F:\CPM\vm_motion_history.ps1:62 char:51
+
The line nr. 62 does not match to the line nr. of your original script, because I added some lines ontop of the script for automatic logon. Do you know what this message means. Is -proterty possibly not available in Powershell V1.0 (We use this version on our servers).
I hope you can help me, because we need the information where the VMs reside in the past for an audit. Because Oracle Licencing depends on how many ESX-hosts the VM runs in total.
Thanks
LarsO
No, PowerShell v1 doesn't know the hash -Property.
But you can easily adapt this for PowerShell v1.
Replace these lines
... $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.*") ...
by these lines
.. $row = "" | Select VMname,Source,Destination,Start,Finish,Result,User,DRS $row.VMname = $task.EntityName $row.Source = $event.Host.Name $row.Destination = $event.DestHost.Name $row.Start = $task.StartTime $row.Finish = $task.CompleteTime $row.Result = $task.State $row.User = $task.Reason.UserName $row.DRS = &{if($task.DescriptionId -like "Drm.*") $migrations += $row ...
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I´ve exactly replaced that lines you suggest, but a new error occured:
Missing statement block after if ( condition ). At :line:72 char:14+ $ <<<< migrations += $row
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" {
$row = "" | Select VMname,Source,Destination,Start,Finish,Result,User,DRS
$row.VMname = $task.EntityName
$row.Source = $event.Host.Name
$row.Destination = $event.DestHost.Name
$row.Start = $task.StartTime
$row.Finish = $task.CompleteTime
$row.Result = $task.State
$row.User = $task.Reason.UserName
$row.DRS = &{if($task.DescriptionId -like "Drm.*")
$migrations += $row
}
}
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)
}
My mistake, the new line for the DRS property was not complete.
Attached the script with the PS v1 way of creating the object.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Great Script
Now it also run on Powershell V1. I´ve done some little modifications, but the main reason was that it was not compatible to Powershell V1.
Thank you very much!
Regards
LarsO