PowerCLI

 View Only
Expand all | Collapse all

Last entry in VMKernel log

  • 1.  Last entry in VMKernel log

    Posted Mar 24, 2021 10:44 AM

    Hi,

    Recently we have come across issue where we found that there are no new messages being logged in the vmkernel log on a VxRail host. Now Dell has advised us to scan all the vxrail hosts in the environment to find date and time of the last entry in the vmkernel log. 

    I know we can use the Get-Log cmdlet to get the vmkernel log entries however I am struggling to fetch the date and time of the last entry/message in the vmkernel.log.

    Please help. 



  • 2.  RE: Last entry in VMKernel log

    Posted Mar 24, 2021 11:41 AM

    Do you have SSH access to the ESXi nodes?



  • 3.  RE: Last entry in VMKernel log

    Posted Mar 24, 2021 12:04 PM

    Yes but there is a challenge as each host has different password.



  • 4.  RE: Last entry in VMKernel log

    Posted Mar 24, 2021 12:10 PM

    Is there any way you can provide a list with hostnames and credentials?
    Otherwise, it will have to be via Get-Log,  which will take quite a bit longer



  • 5.  RE: Last entry in VMKernel log

    Posted Mar 24, 2021 12:15 PM

    Yes it is possible to provide a list with hostnames and credentials however I would request if you can show me both SSH and Get-Log.

     

     



  • 6.  RE: Last entry in VMKernel log
    Best Answer

    Posted Mar 24, 2021 12:26 PM

    This is the Get-Log based one

    Get-VMHost -PipelineVariable esx |
    ForEach-Object -Process {
        Get-Log -Key vmkernel -VMHost $esx |
        Select @{N='VMHost';E={$_.Host.Name}},
            @{N='LastLine';E={$_.Entries[$_.LastLineNum - 1]}}
    }


  • 7.  RE: Last entry in VMKernel log

    Posted Mar 24, 2021 12:52 PM

    Thanks LucD. Much appreciated. It is working like a charm. 



  • 8.  RE: Last entry in VMKernel log

    Posted May 15, 2023 01:10 PM

    Hi, 

    I need further help on this so posting my query here.

    I am trying to fetch Date and time from this last entry of host vmkrnel log like below but I am getting the exception mentioned below. Please let me know how can I convert it to Date and Time format so that I can find out the time difference with the current date and time.

    $lastLine = Get-Log -Key vmkernel -VMHost $esx | Select @{N='VMHost';E={$_.Host.Name}},@{N='LastLine';E={$_.Entries[$_.LastLineNum - 1]}}

    $lastDateTime = $lastLine.LastLine.Split("Z ")[0].ToDateTime($_)

     

    Exception calling "ToDateTime" with "1" argument(s): "String was not recognized as a valid DateTime."
    At D:\PNF-Morning-Checks\VSAN-MorningCheck-Daily.ps1:761 char:6
    + ... $lastTime = $lastLine.LastLine.Split("Z ")[0].ToDateTime( ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FormatException



  • 9.  RE: Last entry in VMKernel log

    Posted May 15, 2023 03:03 PM

    Not sure what you have in $lastLine.LastLine, but assuming it is the last line fo the vmkernel log, can you try casting with DateTime?
    You do not have to drop the 'Z' at the end, rather split on the blank.

    $lastDateTime = [DateTime]($lastLine.LastLine.Split(' ')[0])

     



  • 10.  RE: Last entry in VMKernel log

    Posted May 15, 2023 04:01 PM

    Thanks Lucd for your reply.

    $lastLine.LastLine is giving the last entry of the vmkernel log like below:

    2023-05-15T04:47:37.814Z cpu40:16672)WARNING: LinScsi: SCSILinuxAbortCommands:1816:Failed, Driver hpsa, for vmhba0

    I have tried as you advised but getting the following error:

    Cannot convert value "" to type "System.DateTime". Error: "String was not recognized as a valid DateTime."
    At D:\PNF-Morning-Checks\VSAN-MorningCheck-Daily.ps1:761 char:6
    + ... $lastDateTime = [DateTime]($lastLine.LastLine.Split(' ')[ ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastParseTargetInvocationWithFormatProvider 



  • 11.  RE: Last entry in VMKernel log

    Posted May 15, 2023 04:21 PM

    Seems to work for me

    LucD_0-1684167601170.png

    Do you have a String in $lastLine.LastLine or output from a Select-Object cmdlet?

     



  • 12.  RE: Last entry in VMKernel log

    Posted May 15, 2023 04:40 PM

    It is the output of the following command

    $lastLine = Get-Log -Key vmkernel -VMHost $esx | Select @{N='VMHost';E={$_.Host.Name}},@{N='LastLine';E={$_.Entries[$_.LastLineNum - 1]}}



  • 13.  RE: Last entry in VMKernel log
    Best Answer

    Posted May 15, 2023 05:13 PM

    That is exactly what I just did, and it works for me.

    LucD_0-1684169816875.png

    It could be that your station has regional settings that are not en-US.
    And unfortunately, the DateTime casting uses the en-US setting by default.
    What does the following return?

    Get-Culture

    If that is not en-US, you can force the DateTime conversion to use en-US (as the VMKernel log uses)

    $c = [cultureInfo]::GetCultureInfo('en-US')
    $lastLine.LastLine.Split(' ')[0].ToDateTime($c) 


  • 14.  RE: Last entry in VMKernel log

    Posted May 15, 2023 05:41 PM

    Hi LucD,

    You are just awesome.

    Yes the server is using the regional setting as en-GB.