VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

vCenter field shows blank

Hi,

I am unable to get the vCenter details from the below, please help

Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-7) | Where-Object {$_ -is [VMware.Vim.VmCreatedEvent] -or $_ -is [VMware.Vim.VmRemovedEvent]} | Select | Sort -Property CreatedTime -Descending | Select @{N='vCenter';E={([uri]$_.ExtensionData.Client.ServiceUrl).Host}}, @{N='VM Name';E={$_.VM.Name}}, CreatedTime,UserName,FullformattedMessage 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Like I said earlier, use the Server parameter

$vCenters = "vCenter1","vCenter2"
Connect-viserver -Server $vCenters

$global:defaultviservers |
ForEach-Object -Process {
    $vc = $_
    Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-1) -Server $vc | 
    Where-Object {$_ -is [VMware.Vim.VmCreatedEvent] -or $_ -is [VMware.Vim.VmRemovedEvent]} | 
    Sort -Property CreatedTime -Descending | 
    Select @{N='vCenter';E={([System.Uri]$vc.ServiceUri.AbsoluteUri).Host}}, 
        @{N='VM Name';E={$_.VM.Name}}, 
        CreatedTime,UserName,FullformattedMessage
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
7 Replies
fabio1975
Commander
Commander
Jump to solution

Ciao 


I tried your script and in my infrastructure, it seems to work (i deleted a test VM) and it detects deletion

fabio1975_0-1636473990568.png

what's the problem?

Fabio

Visit vmvirtual.blog
If you're satisfied give me a kudos

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

I am unable to get the vCenter Name in the output

@{N='vCenter';E={([uri]$_.ExtensionData.Client.ServiceUrl).Host} shows blank 

Even in your output, vCenter Name shows blank 🙂

0 Kudos
LucD
Leadership
Leadership
Jump to solution

An Event object does not have an ExtensionData property.

The only way to get the vCenter in there is to launch the Get-VIEvent when you are connected to 1 vCenter, or by using the Server parameter.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
fabio1975
Commander
Commander
Jump to solution

Ciao 

 

Try this 

Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-1) | Where-Object {$_ -is [VMware.Vim.VmCreatedEvent] -or $_ -is [VMware.Vim.VmRemovedEvent]} | Select | Sort -Property CreatedTime -Descending | Select @{N='vCenter';E={([System.Uri]$global:defaultviserver.ServiceUri.AbsoluteUri).Host}}, @{N='VM Name';E={$_.VM.Name}}, CreatedTime,UserName,FullformattedMessage

fabio1975_1-1636486382613.png

 

 

Fabio

Visit vmvirtual.blog
If you're satisfied give me a kudos

ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi Fabio,

I am able to get the vCenter Name now. 🙂 But If I have connected to multiple vCenters then it is not providing the correct vCenter name.

$vCenters = @(
"vCenter1"
"vCenter2"
)
Connect-viserver -Server $vCenters

Both VMs shows the same vCenter Name as vCenter2 rather than respective one`s

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Like I said earlier, use the Server parameter

$vCenters = "vCenter1","vCenter2"
Connect-viserver -Server $vCenters

$global:defaultviservers |
ForEach-Object -Process {
    $vc = $_
    Get-VIEvent -MaxSamples ([int]::MaxValue) -Start (Get-Date).AddDays(-1) -Server $vc | 
    Where-Object {$_ -is [VMware.Vim.VmCreatedEvent] -or $_ -is [VMware.Vim.VmRemovedEvent]} | 
    Sort -Property CreatedTime -Descending | 
    Select @{N='vCenter';E={([System.Uri]$vc.ServiceUri.AbsoluteUri).Host}}, 
        @{N='VM Name';E={$_.VM.Name}}, 
        CreatedTime,UserName,FullformattedMessage
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very much LucD 🙂

0 Kudos