Getting Username from Events

This post was originally published on this site



just wondering what would be the best approach when dealing Events and getting the username from the Events I’m Searching for:


The below doesn’t seem to be exporting correctly that it doesn’t export the Name.



$deployments = $events | where {$_ -is [Vmware.vim.VmBeingClonedEvent] -or $_ -is [Vmware.vim.VmCreatedEvent]}

foreach($deployment in $deployments){
$dataObj = "" | Select-Object events
$ = $events | Where-Object {$_.ChainID -eq $deployment.ChainID}
$deploymentChains += $dataObj
foreach($chain in $deploymentChains) {
$newVM = ($ 
$Exists = get-vm -name $newVM -ErrorAction SilentlyContinue
    $deployedvms += $Exists | Where {$deployedvms -notcontains $_} 
    #Do Nothing
} }

foreach($vm in $deployedvms) {
  $cluster = Get-Cluster -VM $vm | Select Name -ExpandProperty Name
  if($cluster -match $regex -or $cluster -match $regex1){
$userevent = Get-VIEvent -Entity $vm.Name -Start $start -Finish $now -MaxSamples 1 | Select UserName -ExpandProperty UserName | where {$_ -is [Vmware.vim.VmBeingClonedEvent] -or $_ -is [Vmware.vim.VmCreatedEvent]}
        $result = "" | select vmName,ESXname,Powerstate,NumCpu,MemoryGB,ProvisionedSpaceGB
        $result.vmName = $vm.Name
        $result.ESXname = $VM.VMHost
        $result.Powerstate = $vm.Powerstate
        $result.NumCpu = $vm.NumCpu
        $result.MemoryGB = $vm.MemoryGB
$result.ProvisionedSpaceGB = $vm.ProvisionedSpaceGB
  $result | add-member -MemberType NoteProperty -name 'Cluster' -Value $cluster
  $result | add-member -MemberType NoteProperty -name 'vCenter' -Value $item
    $result | add-member -MemberType NoteProperty -name 'UserName' -Value $userevent 
  $results += $result  

Leave a Reply

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