View Only
  • 1.  Get Clone Source

    Posted Jun 17, 2013 05:40 PM

    I'm trying to run a powercli script that, among other things, is trying to get a list of all cloned VMs. One important piece of data in this is what was the original source of that clone. I'm struggling to find that data.

    Whether I run Get-VIEvent and find clone events or run a $filter.Type = "VmClonedEvent" and $events = $em.QueryEvents($filter), I get an object of type "VmClonedEvent" that, while having a SourceVm property, seems to be self-referencing (perhaps the source of the Event) but doesn't refer to the original source VM of the clone.

    Can someone let me know if getting that information is possible and if so where I can find it?

    Any help would be appreciated.

    Thank you.

  • 2.  RE: Get Clone Source
    Best Answer

    Posted Jun 18, 2013 04:17 PM

    Found my own answer.

    Changing the event type to "VmBeingClonedEvent", the Vm.Name property is the Source VM and the DestName is the new VM.

    Here's some sample code for others that may be searching for this:

    # Get EventManager Obj
    $em = get-view (get-view ServiceInstance).Content.EventManager

    # Instantiating Event Filter
    $filter = New-Object VMware.Vim.EventFilterSpec

    echo "$(date -format s) - Getting VM Clone Events"
    $filter.Type = "VmBeingClonedEvent"
    $cloneEvents = $em.QueryEvents($filter)

    echo "$(date -format s) - Looping through VM Clone Events"
    $cloneObjs = @()
    foreach ($nextEvent in $cloneEvents) {

        echo "$(date -format s) - Next VM Clone: $($nextEvent.Vm.Name) -> $($nextEvent.DestName)"
        $o = New-Object System.Object
        $o | add-member NoteProperty CreatedTime $nextEvent.CreatedTime # datetime VM was cloned
        $o | add-member NoteProperty UserName $nextEvent.UserName # name of the user who cloned the VM
        $o | add-member NoteProperty SourceVMName $nextEvent.Vm.Name # name of the VM
        $o | add-member NoteProperty NewVMName $nextEvent.DestName # name of the VM
        $o | add-member NoteProperty Message $nextEvent.FullFormattedMessage # message associated with event
        $cloneObjs += $o