Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 223568

Re: Get Clone Source

$
0
0

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
}


Viewing all articles
Browse latest Browse all 223568

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>