Automation

 View Only
  • 1.  vCenter shows blank in output for VMHost Events Info

    Posted Aug 29, 2024 03:07 AM

    Hi,

    For below script, I am unable to get the vCenter Information as it shows blank in the output.

    Please help!!

    #VMHosts List
    function get-VMHostEvents()
    {
    $servs = @'
    VMHost
    ESXi01

    ESXi02
    '@
    ForEach ($serv in (ConvertFrom-Csv -InputObject $servs).VMHost)
    {
    Get-VIEvent -Entity (get-vmhost $serv) -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValue) | select @{N='vCenter';E={([uri](Get-View -Id $_.Entity.Entity -Property Client).Client.ServiceUrl).Host}},
        @{N='Cluster';E={$_.ComputeResource.Name}},
        @{Name='host';E={$_.Host.name}},
        @{Name='IPAddress';E={$_.IPAddress}},
        @{N='user';E={$_.UserName}},
        @{N='Createdtime'; E={$_.CreatedTime}},
        @{N='Fullmessage';E={$_.FullFormattedMessage}} -ExcludeProperty PSComputerName,RunSpaceId,PSShowComputername
    }
    }
    get-VMHostEvents | Export-Excel -Path $reportlocation -AutoFilter -AutoSize -BoldTopRow -FreezeTopRow -WorksheetName VMHost_Event_Info



  • 2.  RE: vCenter shows blank in output for VMHost Events Info

    Posted Aug 29, 2024 03:35 AM

    Works for me (vSphere 8.*).
    Can you check that the returned events have a value in the Client property?



    ------------------------------


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


    ------------------------------



  • 3.  RE: vCenter shows blank in output for VMHost Events Info

    Posted Aug 29, 2024 06:02 PM

    Hi LucD,

    I am using vSphere 7, still I am getting the same error

    No I dont see returned values are having anything like Client property




  • 4.  RE: vCenter shows blank in output for VMHost Events Info

    Posted Aug 29, 2024 06:03 PM

    And what is shown under the Entity property of the returned events?



    ------------------------------


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


    ------------------------------



  • 5.  RE: vCenter shows blank in output for VMHost Events Info

    Posted Aug 30, 2024 06:01 AM

    Tested against version 7 and 8 vCenter with PowerCLI 7.0.3.1: the returned Event Object does not have an Entity property.

    v7

    IpAddress            : 127.0.0.1
    UserAgent            : pyvmomi Python/3xxxx (VMkernel; 7.0.3; x86_64)
    CallCount            : 7
    SessionId            : 5xxxxxxxxxxxxxxxxxx
    LoginTime            : 30.08.2024 07:09:17
    Key                  : 6x7xxx
    ChainId              : 67xx57x
    CreatedTime          : 30.08.2024 07:09:17
    UserName             : root
    Datacenter           : VMware.Vim.DatacenterEventArgument
    ComputeResource      : VMware.Vim.ComputeResourceEventArgument
    Host                 : VMware.Vim.HostEventArgument
    Vm                   :
    Ds                   :
    Net                  :
    Dvs                  :
    FullFormattedMessage : xxxxxxxxxxxxxxxxxxxxxxxxxxx
    ChangeTag            :

    v8

    IpAddress            : 127.0.0.1
    UserAgent            : pyvmomi 8.0xxxxx internal Python/3.xxxxxxxxx+ (VMkernel; 8.0.3; x86_64)
    CallCount            : 7
    SessionId            : xxxxxxxxxxxxxxxxx
    LoginTime            : 30.08.2024 07:08:12
    Key                  : 173xxxxxxxxxxxx
    ChainId              : 1735xxxxxxxxxxxxxx
    CreatedTime          : 30.08.2024 07:08:12
    UserName             : root
    Datacenter           : VMware.Vim.DatacenterEventArgument
    ComputeResource      : VMware.Vim.ComputeResourceEventArgument
    Host                 : VMware.Vim.HostEventArgument
    Vm                   :
    Ds                   :
    Net                  :
    Dvs                  :
    FullFormattedMessage : Uxxxxxxxxxxxxxxxx
    ChangeTag            :

    I think the problem here seems to be that you are looking for a property in the event object that is inside the VMHost-Object.

    Try this (replacing your 12th line starting with Get-VIEvent):

    $thisVMHost = get-vmhost $serv; Get-VIEvent -Entity $thisVMHost -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValue) | select @{N='vCenter';E={$thisVMHost.ExtensionData.Client.ServiceUrl}},



  • 6.  RE: vCenter shows blank in output for VMHost Events Info

    Posted Aug 30, 2024 06:05 AM

    "Tested against version 7 and 8 vCenter with PowerCLI 7.0.3.1: the returned Event Object does not have an Entity property."

    That is not correct I'm afraid, the Entity property is there, it just isn't present in all Event types.
    See for example AlarmStatusChangedEvent



    ------------------------------


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


    ------------------------------



  • 7.  RE: vCenter shows blank in output for VMHost Events Info
    Best Answer

    Posted Aug 30, 2024 06:01 AM

    I just noticed that the Entity property is blank in some cases, not in all events.
    The property is there for example for AlarmStatusChangedEvent events.

    Asn an alternative try like this

    #VMHosts List
    function get-VMHostEvents() {
      $servs = @'
    VMHost
    ESXi01
    
    ESXi02
    '@
      ForEach ($serv in (ConvertFrom-Csv -InputObject $servs).VMHost) {
        $esx = Get-VMHost -Name $serv
        Get-VIEvent -Entity $esx -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValue) | 
        Select-Object @{N = 'vCenter'; E = { ([uri]$esx.ExtensionData.Client.ServiceUrl).Host } },
        @{N = 'Cluster'; E = { $_.ComputeResource.Name } },
        @{Name = 'host'; E = { $_.Host.name } },
        @{Name = 'IPAddress'; E = { $_.IPAddress } },
        @{N = 'user'; E = { $_.UserName } },
        @{N = 'Createdtime'; E = { $_.CreatedTime } },
        @{N = 'Fullmessage'; E = { $_.FullFormattedMessage } } -ExcludeProperty PSComputerName, RunSpaceId, PSShowComputername
      }
    }
    
    get-VMHostEvents | 
    
    Export-Excel -Path $reportlocation -AutoFilter -AutoSize -BoldTopRow -FreezeTopRow -WorksheetName VMHost_Event_Info



    ------------------------------


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


    ------------------------------



  • 8.  RE: vCenter shows blank in output for VMHost Events Info

    Posted Sep 05, 2024 01:08 AM

    Thank you very much LucD. that worked :)