I was curious to know why I was getting different results with storage vMotion using vSphere 5 and using the above examples to fetch svMotion events, so I had a bit of a further play around with this in my lab setup this evening.
The reason why I saw svMotions only when searching for events using this cmdlet:
$events = Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddMonths(-1) | Where {$_.GetType().Name -eq "TaskEvent" -and $_.Info.DescriptionId -eq "StorageResourceManager.applyRecommendation"} | Select CreatedTime, UserName, FullFormattedMessage
is because of SDRS and Datastore Clusters it would seem. When you svMotion a VM between Datastore Clusters, the event seems to be come through under Recent Tasks as "Apply Storage DRS recommendations". However, if you svMotion the VM into a normal Datastore, which is not part of a Datastore cluster, then it comes through as "Relocate virtual machine". This is the difference, and hence the reason when I first tried earlier that I saw the event only when searching for "StorageResourceManager.applyRecommendation". (I was testing svMotion by moving a VM between two datastore clusters).
Now, I disassembled a datastore cluster to create a couple of normal datastores and migrated some VMs around these - the events now come up as expected as "Relocate virtual machine".
So what that means is if you are using Datastore Clusters with vSphere 5 only, then you should use the example above in this post. If you are using normal datastores in vSphere 4 or 5, then use Luc's example in his first post. Or, if you want to cover all your bases and are using both normal Datastores and Datastore clusters, then the following should work:
$events = Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddMonths(-1) | Where { $_.GetType().Name -eq "TaskEvent" -and $_.Info.DescriptionId -eq "VirtualMachine.relocate" -or $_.Info.DescriptionId -eq "StorageResourceManager.applyRecommendation"} | Select CreatedTime, UserName, FullFormattedMessage
This will give you a list of both types of storage vMotion that have occurred.
Here is an example in my environment (vSphere 5) where I have svMotioned between DS clusters and normal Datastores:
Message was edited by: Shoganator - Syntax highlighting!