# Get the vMotion/svMotion history

The availability of vMotion and svMotion, provided you have a license that allows it, in vSphere are some of its key features.

The DRS and SDRS functionality will use vMotion and svMotion to better use the available resources.

And you as a vSphere administrator can use it to facilitate your work. Just think of how easy patching or datastorecluster maintenance becomes with the help of these two features.
But as an administrator you want to be able to report on what vMotion and svMotion have been doing over a specific time interval in your vSphere environment.

In the past I already provided a vMotion reporting tool in Events – Part 8 – vMotion history, but now it was time to provide a universal (s)vMotion reporting feature.

• User: one or more users for which to return the events
• System: a switch to return all system user events

Update February 10th 2014: it’s always nice to see another implementation based on one of your scripts. The Opvizor solution will soon contain this function, see Dennis Zimmer‘s post called Storage vMotion Activities Report !

## The Script

#### Annotations

Line 1-101: The Get-VIEventPlus function. This function adds some improvements, at least for me, to the current Get-VIEvent cmdlet. It allows you to specify which specific events to return and it allows you to use a ‘recursive’ search for events starting from the ‘Entity’.

Line 52: The function uses the EventHistoryCollector. Access to the found events is through a ‘sliding‘ window. This variable defines the size of that sliding window. From my average use, I came to the conclusion that 100 events is a workable size for this window. But your mileage may vary.

Line 55-85: These lines are the hearth of the function. In here the ‘filter‘ is specified for the events to search for. See the EventFilterSpec objects for the details.

Line 89: The EventFilterSpec can hold only one MoRef. So if multiple entities are passed, they will have be handled one by one. This makes a big difference in execution time when you do not select the value for the Entity parameter correctly. See later.

Line 93-96: This While construction reads all the found events.

Line 103-187: The Get-MotionHistory function. This function uses the Get-VIEventPlus function to retrieve specific events. The returned events are used to report on all the vMotions and svMotions.

Line 140-145: The function has 3 parametersets, each indicating a specific type of interval (Days/Hours/Minutes). The default is 1 day back in time.

Line 151: Since the function supports pipeline input, the history records it creates must be stored in an array until all pipeline objects have been handled.

Line 152-162: The 3 parametersets are handled with a Switch statement, and the Start parameter for the Get-VIEvent cmdlet is calculated accordingly.

Line 163: For the (s)vMotion history the function only needs these 2 types of events.

Line 171: The vMotion and or svMotion actions can be user invoked or system invoked (DRS/SDRS)

Line 173-176: Depending on the type of ‘motion‘, the functions will include a target host or target datastore.

## Sample Usage

The Get-MotionHistory function is quite simple to use as the following example will show.

The content of the produced CSV looks like this.

When you use the Get-MotionHistory take care of what you pass on the Entity parameter !

The following calls will produce the same result.

as this one

But the difference between these two calls of the function is the execution time. The second method was 80 times slower compared to the first method in my test environment, where there are about 100 VMs in that cluster.

The reason is that the Get-VIEventPlus function has to call the EventHistoryCollector for each VM in the 2nd method, while it is only called once in the 1st method !

That is also the main reason I introduced the Recurse parameter on the Get-VIEventPlus function. A feature that is sadly missing on the Get-VIEvent cmdlet 😥

If you want to have a report for a specific set of VMs in a cluster, it is most probably better to call the Get-MotionHistory function for the complete cluster with the Recurse switch set to $true, and filter out the required VMs from the produced result. Something like this for example Enjoy ! ##### 89 Comments #### GeertC Hi LucD been a long time fan of Get-VIEventPlus From the moment we started using vCenter 7.x it stopped working. when using “Get-VIEventPlus” I don’t get any output when using “Get-VIEvent”, I get the output expected any tip where I need to look at ? #### LucD Hi, The function still seems to work for me. But in vSphere 7.* I noticed that the EventType has become case-sensitive. For example  Get-VIEventPlus -Start (Get-Date).AddDays(-1) -EventType VMConnectedEvent  doesn’t return anything. But  Get-VIEventPlus -Start (Get-Date).AddDays(-1) -EventType VmConnectedEvent  does. Could that also be what you are experiencing? #### [SOLVED] How do I get events associated with Datastores and Datastore Clusters using PowerCLI? – BugsFixing […] I posted this I did some more digging and found that Luc Dekens wrote another function calledGet-VIEventPlus. This doesn’t work out of the box because -Entity expects a type of […] #### Ashraf Ali J This really help me a lot, can you add Status of vMotion – Successful or Failed #### LucD Afaik, the events VMMigratedEvent and DrsVmMigratedEvent are only created when the migration was successful. There is a VmFailedMigrateEvent that shows failed migrations. But that event is not handled in this snippet #### Nitin I am getting below error, Get-MotionHistory : The term ‘Get-MotionHistory’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:32 + Get-Cluster -Name sesovic028 | Get-MotionHistory -Hours 4 -Recurse:$t …
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-MotionHistory:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

#### Nitin

Below is the vmware module version

irectory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version Name ExportedCommands
———- ——- —- —————-
Manifest 12.3.0…. VMware.PowerCLI

#### LucD

It looks as if you didn’t ‘source’ the functions before calling them.

Just copy the functions to a .PS1 file, and then ‘source’ that .PS1 file.
You can do that as follows from your PS prompt.
 . .\filename.ps1 
Note that there is a blank between the 2 dots.

#### moellerj

Hi Lucd,
we Updated to vCenter 7.0.U2b , Get-MotionHistory stucks now.
There may have been changes here, that lead to the problem.
Can you say something about that?
BR
moellerj

#### LucD

Hi,
Do you have any more details?
What do you mean by “Get-MotionHistory stucks now“?

I’ll do some testing with 7.0 U2b as well.

#### JacquesM

Hello Luc!

As usual impressive script.
I was looking at getting also if the VM was running at the time of event (for svmotion)
@{N=”PowerState”;E={$_.VM.PowerState}}, as ligne 167… With no luck… Any chance that the powerstate of VM during an event is available for export into the csv? thanks a lot! #### LucD Hi Jacques, Thanks. I’m afraid the powerstate of the VM is not included in the events the script uses. The VmMigratedEvent for example has a VM property, but that only contains the MoRef to the VM. You could use events to determine if a VM was powered on at the time of the vMotion, by retrieving the VmPoweredOnEvent and VmPoweredOffEvent. And then checking what was the last event just before the vMotion. Luc #### JacquesM Thanks Luc! Thanks for your hard work! I will try to bring up this. Cheers! Jacques #### Eugene As usual, LucD’s scripts always works. Just copy/paste and no problem. Thanks sharing your knowledge #### LucD Well, thank you! #### MB Hi Luc, its really a nice script to pull vmotion information. How ever the target datastore information was not coming. @{N=”TgtDatastore”;E={if($_.Ds.Name -ne $_.SourceDatastore.Name){$_.Ds.Name}}}

Also can you please give me the lines of code to get start time, end time and execution time of vmotion and where to add those lines in script.

if possible vm cluster name (before and after)

#### Event-O-Matic - LucD notes

[…] the Get-VIEventPlus switch, you can generate code that uses the Get-VIEventPlus function. See my Get the vMotion/svMotion history post for the Get-VIEventPlus […]

[…] analogy with the Get-VIEventPlus function, I published in my Get the vMotion/svMotion history post, here is the Get-TaskPlus function […]

#### basem

Hi

How many days can i get back to check the vmotion migrations ?

Basem

#### LucD

As many days as you keep Events for.

You can check how long events are kept with
 Get-AdvancedSetting -Entity $global:defaultVIServer -Name "event.maxAge" Get-AdvancedSetting -Entity$global:defaultVIServer -Name "event.maxAgeEnabled" 

#### John B.

Thank you for the functions parameters, this has helped me and modified for my final output. Thank you LucD for another great example

#### sudhakar

How to get the report for the specific set of VMs in the .txt file. I want to know the vMotion history for the set of VMs for the past 30 days. How to accomplish it.

#### LucD

You could do something like this.
It assumes that the names of the VMs are each on a separate line in the .txt file.
 Get-MotionHistory -Entity (Get-VM -Name (Get-Content -Path .\vmnames.txt)) -Days 30 

#### matze

Hi LUCD,
we will use your script for our audit. Is it possible to add a new column next to the Src-ESXi / Trg-ESXi with hardware informations for example CPU (Cores, clock speed); vendor of the server, RAM, etc.)?

Kind regards
Matze

#### Tanmay

How can we add completion time in script

#### LucD

Hi Tanmay,
You can follow the related events, and from the TaskEvent determine the start time.
Something like this for example
 $events = Get-VIEvent -Start (get-Date).AddDays(-1) -MaxSamples ([int]::MaxValue)$events | where{$_ -is [VMware.Vim.VmRelocatedEvent]} | ForEach-Object -Process {$chain = $_.ChainId$chained = $events | where{$_.ChainId -eq $chain} | Sort-Object -Property CreatedTime$task = $chained | where{$_ -is [VMware.Vim.TaskEvent] -and $_.Info.Name -eq 'RelocateVM_Task'} if($task){ New-Object PSObject -Property @{ VM = $chained[0].Vm.Name Type =$task.Info.Name User = $task.Info.Reason.UserName Start =$task.Info.QueueTime Finish = ($chained | where{$_ -is [VMware.Vim.VmRelocatedEvent]}).CreatedTime } } } 

#### Mathias

Hi Lucd,
is it possible to attach the completion time in the script in the top?
Kind regards
Matthias

#### Jochen

Hi LucD

Great function you create, it helps me a lot of monitor my environment.

Is it possible to add Start / End Time of migration to your function output? That is the only thing I additional need.

Thanks a lot for your great work!

Kind regards
Jochen

#### nabil rouijel

Can i get history of svMotion by name of cluster datastore source and cluster datastore destination ?
thank you

#### rouijel

fonctionne parfaitement Merci !
en revanche je cherche le nom de l\’objet Datastore cluster source et datastore cluster déstination comme pour le datastore source \”sourcedatastore.name\” car je veux superviser si une VM change de cluster datastore

Merci par avance

#### T.K

I can’t figure out where in your script to convert the Events’ Start and End Time from UTC to my local time? Could you help me out please?

#### LucD

Hi T.K.,
Try replacing line 168 with
 Select @{N='CreatedTime';E={$_.CreatedTime.TolocalTime()}},  #### Tina K Thank you Luc. That worked! #### LT I didn’t look too close in the function but It didn’t work in my environment (VMware 5.5). I came up with this that go through each VM and looks for datastore event. It has a start time and finish time as I wanted to calculate the time it took to vMotion each machine.$VMotions = @()

get-vm | foreach {
$VM =$_.name
“Querying $VM” Get-VIEvent -Entity$vm -MaxSamples 10000 | ?{$_.ds -ne$null} | foreach {
$VMotions += New-Object PSObject -Property @{VMName=$VM ; StartTime=$_.CreatedTime ; Message=$_.FullFormattedMessage}
}

}

Tweak it as per your need.

#### LucD

What problems did you encounter with the function?

#### Lucas

Hi, LucD. Great article and great script. Thank you for that.
I’m getting 4 days of vMotions in the output.

Do you know how to extend it?
Best regards

#### Lucas

I forgot to write that the vCenter task and events settings is configured to 30 days

#### Mohamed Elsaid

Hallo LucD..
Thanks for the script. I run it but it gives me blank columns. Although I have done many vMotions. Can you kindly advise?

Mohamed

#### Ryan Patigayon

I got blank output in any parameter, so i modified script from practical admin and working with this output.

Name Created UserName Type SourceHost TargetHost Datacenter

#### LucD

Hi Ryan,
Not sure what could be causing this.
Would you mind sharing the code you used to call the function?

#### Mohamed Elsaid

Hallo LucD..
Thanks for the script. I run it but it gives me blank columns. Although I have done many vMotions. Can you kindly advise?

Mohamed

#### LucD

Hi Mohamed,
You could first check if you are keeping the Tasks and Events sufficiently long in your vCenter.
By default they are kept for 1 year, but that could have been overridden.
Can you check which retention period is set in your environment?
Luc

#### Surendra Mannepalli

Dear Luc,

I have zero knowledge in scripting ,I am sending the script which i am unable execute, please correct that. please mail me and help me.
My emailid: surendra.windows@gmail.com

function Get-MotionHistory {
param(
[CmdletBinding(DefaultParameterSetName=”Days”)]
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]$prvm-vcsrv.mcgm.gov.in, [Parameter(ParameterSetName=’Days’)] [int]$Days = 1,
[Parameter(ParameterSetName=’Hours’)]
[int]$Hours, [Parameter(ParameterSetName=’Minutes’)] [int]$Minutes,
[switch]$Recurse =$false,
[switch]$Sort =$true
)

param(
[CmdletBinding(DefaultParameterSetName=”Days”)]
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]$prvm-vcsrv.mcgm.gov.in, [Parameter(ParameterSetName=’Days’)] [int]$Days,
[Parameter(ParameterSetName=’Hours’)]
[int]$Hours, [Parameter(ParameterSetName=’Minutes’)] [int]$Minutes,
[switch]$Recurse =$false,
[switch]$Sort =$true
)

begin{
$history = @() switch($psCmdlet.ParameterSetName){
‘Days’ {
$start = (Get-Date).AddDays(-$Days)
}
‘Hours’ {
$start = (Get-Date).AddHours(-$Hours)
}
‘Minutes’ {
$start = (Get-Date).AddMinutes(-$Minutes)
}
}
$eventTypes = “DrsVmMigratedEvent”,”VmMigratedEvent” } process{$history += Get-VIEventPlus -Entity $entity -Start$start -EventType $eventTypes -Recurse:$Recurse |
Select CreatedTime,
@{N=”Type”;E={
if($_.SourceDatastore.Name -eq$_.Ds.Name){“vMotion”}else{“svMotion”}}},
@{N=”UserName”;E={if($_.UserName){$_.UserName}else{“System”}}},
@{N=”VM”;E={$_.VM.Name}}, @{N=”SrcVMHost”;E={$_.SourceHost.Name.Split(‘.’)[0]}},
@{N=”TgtVMHost”;E={if($_.Host.Name -ne$_.SourceHost.Name){$_.Host.Name.Split(‘.’)[0]}}}, @{N=”SrcDatastore”;E={$_.SourceDatastore.Name}},
@{N=”TgtDatastore”;E={if($_.Ds.Name -ne$_.SourceDatastore.Name){$_.Ds.Name}}} } end{ if($Sort){
$history | Sort-Object -Property CreatedTime } else{$history
}
}
}

At C:\powershell\Get-MotionHistory.ps1:6 char:77
+ [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]$prvm-vcs … + ~ Missing ‘)’ in function parameter list. At C:\powershell\Get-MotionHistory.ps1:2 char:28 + function Get-MotionHistory { + ~ Missing closing ‘}’ in statement block. At C:\powershell\Get-MotionHistory.ps1:15 char:3 + ) + ~ Unexpected token ‘)’ in expression or statement. At C:\powershell\Get-MotionHistory.ps1:20 char:77 + [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]$prvm-vcs …
+ ~~~~
Unexpected token ‘-vcsrv’ in expression or statement.
At C:\powershell\Get-MotionHistory.ps1:20 char:83
+ … l[]]$prvm-vcsrv.mcgm.gov.in, + ~~~~~~~~~~~~ Unexpected token ‘.mcgm.gov.in’ in expression or statement. At C:\powershell\Get-MotionHistory.ps1:20 char:83 #### Nick How complex would it be to add the end time of the task? #### chris Works great, but the reported time is 2 hours behind. My vCenter and ESXi has NTP configured and shows the correct time. Any guess? #### LucD Hi Chris, I suspect this due to the fact the vSphere internally stores all events in UTC. When you retrieve them, they come out with a UTC timestamp. You can easily change it to your local TZ with $_.CreatedTime.ToLocalTime() 
Hope this helps.
Luc

#### Oliver

Hi, I’m trying to use this against vCenter 6 (tried PowerCLI 5.1/6) and it just gives me no results like it’s not even trying. No error or anything.

Any ideas?

#### LucD

Sorry to hear that Oliver.
Would you mind sharing the script with which you call the function ?
And are there any error messages ?

#### Yvan Comte

Hi Luc

Quick question. I am trying to use your script to collect (s)vmotion info from 2 different vcenters (I connect at the beginning of the script, then I pass a system.array populated with a list of VM object I read from a csv list of VMs

foreach ($MyVM in$OSSvm_List) {
$OSSVM += ($MyVM.Host) }
get-MotionHistory -Entity (get-vm $OSSVM) -days$Nbr_days

the problem I have is that I get VM in the $history that are not at all in the import list nor in the system.array variable I pass to your get-MotionHistory fct? Any idea? Help very much appreciated and thanks the great contribution to the community #### LucD Hi, Do these extra VMs you are getting back, have a name that is similar to the ones you did pass to the function ? For example, you include the VM name VM123, but you also get back VM1234. #### Yvan Comte Hi Luc No, the returned VM are not in the system array I am passing. When I breakpoint and look at$entity passed (e.g. line 52) I see the correct VM list. Then it process and the output includes VMs that are not required.
As said I connect to 2 vcenters, but “should” not be an issue. Actually what I do to produce the report is pipe the output of get-MotionHistory liek this:

#### Nathan

Very cool script. Came in very handy. I typically avoid downloading other people’s scripts in my environment, but it really seemed like there wasn’t a better way to accomplish what you are doing here. I was able to expand this very easily to accomplish the task I was looking to do – which was essentially to determine what host a server was located on for a certain date.

#### LucD

Glad it was useful for you

#### Anil

Hello,
Great it works like a charm,
But here in my environment all the hosts connected to vCenter with IP addresses, so when i generate the report in the srcVMhost it is showing only 192 instead of full IP address even in dest also. Any thing need to chenge from the script to get the complete IP address.

Thanks,
Anil

#### Scott

Thanks LucD,

This has been very helpful in the past few days as we have MS Auditors wanting to know how many times our SQL Servers have vMotioned in the past 90 days.

However, I have just noticed that the script doesn’t include DRS relocation event triggered by the Power On virtual machine task. But they have only asked for vMotions so that is ok 🙂

Thanks.
I’ll check if I can include those vMotions as well in the script.

#### Ron

Were you able to get the script to search for sql servers moved via drs
We have the same audit

Thanks
Ron

Hi Ron,
For finding VMs that contain the SQL Server sw you will need a list with those servers, or a script that queries inside the Guest OS.

To catch all vMotions and svMotions you might want to change line 163 to
 $eventTypes = "DrsVmMigratedEvent", "VmMigratedEvent", "VmRelocatedEvent"  #### Ron Thanks I am fine with the script and I am getting vmotion hits per VM with date time and system but both host source host destination show 10 for every vmotion. It doesn’t show me the actual host name in either column. Any ideas on why this would be or what I should do? #### LucD Is the name of that ESXi node perhaps an IP address? The script assumes that the ESXi name is an FQDN, hence the split on the dot on lines 173-174. You can change that like this  @{N="SrcVMHost";E={$_.SourceHost.Name}}, @{N="TgtVMHost";E={if($_.Host.Name -ne$_.SourceHost.Name){$_.Host.Name}}},  #### Ron Hi “Thank you” I am half way there Source IP is now resolved but Destination is still 10. IP addresses are fine. Below is the code I pasted as suggested and my results are shown as well. @{N=”UserName”;E={if($_.UserName){$_.UserName}else{“System”}}}, @{N=”VM”;E={$_.VM.Name}},
@{N=”SrcVMHost”;E={$_.SourceHost.Name}}, @{N=”TgtVMHost”;E={if($_.Host.Name -ne $_.SourceHost.Name){$_.Host.Name.Split(‘.’)[0]}}},
@{N=”SrcDatastore”;E={$_.SourceDatastore.Name}}, @{N=”TgtDatastore”;E={if($_.Ds.Name -ne $_.SourceDatastore.Name){$_.Ds.Name}}}
}
CreatedTime Type UserName VM SrcVMHost TgtVMHost SrcDatastore TgtDatastore
2/18/2022 23:35 vMotion System my-vmname 10.24.50.45 10 B2_Restore_01
2/18/2022 23:35 vMotion System my-vmname 10.24.50.45 10 B2_Restore_Mail13
2/18/2022 23:45 vMotion System my-vmname 10.24.50.37 10 B2_Restore_03

#### Ron

Hi thanks, I change lines 173 and 174 as you suggested and that changed the source address from 10 to the right ip address but the destination address is still 10 not an IP address just 10.

Thanks
Ron

#### LucD

That line should be
 @{N=”TgtVMHost”;E={if($_.Host.Name -ne$_.SourceHost.Name){$_.Host.Name}}},  #### Yoav Slama Thanks for your script but it doesn’t work for me, no matter which parameters i used i always get a blank CSV file, please help me. Thanks. #### LucD Do you have some more details on what you did ? How did you call the function ? From the prompt, from another script ? Any error messages ? #### Yoav Slama Before i executed the script i added according to your examples another command in the end of the script, for example: Get-MotionHistory -Entity (Get-VM VM*) -Days 1 | Export-Csv C:\motion-report1.csv -NoTypeINformation -UseCulture After that i executed your script (./ScriptName). I also tried all of your examples, and i tried to change their parameters but nothing helped, the output is blank every single time with no errors. PowerCLI version: 5.0.1.4431 and 5.5.0.5836 (tried to execute the script on each one of them) vCenter version: 4.1 and 5.1 (tried to execute the script on each one of them) Thanks for your help! #### Yoav Slama I tried to execute the script by adding according to your examples another command in the end of the script, for example: Get-MotionHistory -Entity (Get-VM VM*) -Days 1 | Export-Csv C:\motion-report1.csv -NoTypeINformation -UseCulture I tried all of your examples, and i also tried to change their parameters but nothing helped, the output is blank every single time with no errors (i executed the script by writing: ./NameOfTheScript.ps1 in the PowerCLI command line). PowerCLI version: 5.0.1.4431 and 5.5.0.5836 (i tried to execute the script on each one of them) vCenter version: 4.1 and 5.1 (i tried to execute the script on each one of them) Thanks for your help! #### Rocky From where and how to run these script??????? What are the pre-requisites?? How to understand, what needs to be modified?? Thanks for quick reply #### ranjit when i run the “Get-MotionHistory -Entity (Get-VM VM*) -Days 1 | Export-Csv C:\motion-report1.csv -NoTypeINformation -UseCulture” it creates blank file. #### Zach I keep getting an Input dialog box pop up running the script with : Get-Cluster -Name Cluster1 | Get-MotionHistory -Hours 4 -Recurse:$true
Export-Csv C:\motion-report1.csv -NoTypeINformation -UseCulture

Hi Zach,
Did you pipe the results of the function call to the Export-Csv cmdlet ?
The vertical bar at the end of the 1st line ?
 Get-Cluster -Name Cluster1 | Get-MotionHistory -Hours 4 -Recurse:$true | Export-Csv C:\motion-report1.csv -NoTypeINformation -UseCulture  If that doesn’t solve the issue, what is the exact message you are seeing ? #### keith Great Script! I am able to get everything functioning except the sourcedatastore.name. Any ideas on why it would not populate? #### akamac Hi, Luc. How can I find out possible values for event type? #### internetrush Method invocation failed because [System.Object[]] doesn’t contain a method named ‘CreateCollectorForEvents’. At line:57 char:69 +$eventCollector = Get-View ($eventMgr.CreateCollectorForEvents <<<< ($eventFilter))
+ CategoryInfo : InvalidOperation: (CreateCollectorForEvents:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

You cannot call a method on a null-valued expression.
At line:58 char:53
+ $eventsBuffer =$eventCollector.ReadNextEvents <<<< ($eventnumber) + CategoryInfo : InvalidOperation: (ReadNextEvents:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull You cannot call a method on a null-valued expression. At line:63 char:39 +$eventCollector.DestroyCollector <<<< ()
+ CategoryInfo : InvalidOperation: (DestroyCollector:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Code does not work when passing a single vm using the most recent powercli

#### Matt Andes

Luc,

I was playing around with your Get-VIEventPlus function while working on something else and it appears that the CreatedTime property on the events that the function spits out are in UTC.

Funny thing is that the start and finish date I gave it were in local time and it pulled all of the correct events but the output it gave me had the UTC time which made it weird and was playing havoc with my script because according to the output the last event was after my finish time parameter.

Is this intended? As a side note I was able to get around this by adding this before you spit out the events on line 65:

Foreach ($event in$events) {
$event.CreatedTime =$event.CreatedTime.ToLocalTime()
}
$events #### admin That is correct, the Tasks and Events when retrieved with a HistoryCollector are indeed returning UTC timestamps. I’ll add a switch to the function that allows you to select LocalTime. #### Prabhurj Hello LucD, Thanks for the Nice script, Get-MotionHistory does not works on powercli version 5.1 release 1 and 2? any alternate version that you suggest? Thanks, Prabhu #### Methone Hello, Is it possible to bring svmotion and vMotion History in vCheck I really appreciate that Best regards #### michael works perfectly now, thanks! #### michael thanks Luc, this script came in very handy for checking an specific issue we had. I received the below error but it still provided the results we needed when running: Get-Cluster -Name “*cluster*” | Get-MotionHistory -Hours 4 -Recurse:$true

Exception setting “endTime”: “Cannot convert null to type “System.DateTime”.”
At C:\vmware\vmotion.ps1:52 char:7
+ $eventFilter.time.endTime =$Finish
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting

@Michael, it looks as if that was a “feature” in the Get-VIEventPlus function 😉 Nice catch.
I changed the function slightly, the Finish parameter now has a default value.
Can you check if that solves your problem ?

#### Robert van den Nieuwendijk

Cool stuff as always. I specially like the Get-VIEventPlus -Recurse parameter.

#### LucD

Thanks Robert.

This site uses Akismet to reduce spam. Learn how your comment data is processed.