Automation

 View Only
  • 1.  Get-VIEvent command line options

    Posted Dec 06, 2008 11:51 AM
    Hello list,
    I have a query regarding the command line options for Get-VIevent. i need to get the logs in between a specified period of time. I am going to use this command in a script. so can I make use of Get-Date command output to -Start and -Finish parameters.
    I have to get the logs in between a specified period of time. for example i need logs in between 4 PM to 5 PM in the same day. for that can I make use of Get-Date command output?
    Thanks,
    krishnaprasad



  • 2.  RE: Get-VIEvent command line options

    Posted Dec 06, 2008 12:57 PM

    Yes, you can.

    There are multiple possibilities.

    1) Give an explicit date/time

    Get-VIEvent -Type Error -Start ([DateTime]"2008-12-05 16:00") -Finish ([DateTime]"2008-12-05 17:0")
    

    2) Give relative date/time

    Get-VIEvent -Type Error -Start ((Get-Date).AddHours(-12)) -Finish ((Get-Date).Addhours(-1))
    

    I suspect in your case option 1 would be the best way to go.



  • 3.  RE: Get-VIEvent command line options

    Posted Dec 06, 2008 01:50 PM

    Thanks LucD.

    But my concern is how to use Get-Date output in this command. i will have to get the logs only in some intervals by referrring the current time and previous time. is there a way to do that?

    Thanks

    Krishnaprasad



  • 4.  RE: Get-VIEvent command line options

    Posted Dec 06, 2008 03:46 PM

    For the current time you can use the -Finish parameter with just the Get-Date cmdlet.

    Get-VIEvent -Type Error -Start ((Get-Date).AddDays(-1)) -Finish (Get-Date)
    

    I'm not sure what you mean exactly with "previous time".

    Is that for example 1 day ago ?

    Then you can use the Start parameter is in the example.



  • 5.  RE: Get-VIEvent command line options

    Posted Dec 06, 2008 03:56 PM

    Finish can be left off if you want it to be "now".


    [PowerShell MVP|https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], VI Toolkit forum moderator

    Author of the upcoming book: Managing VMware Infrastructure with PowerShell

    Co-Host, PowerScripting Podcast (http://powerscripting.net)

    Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org



  • 6.  RE: Get-VIEvent command line options

    Posted Dec 07, 2008 12:25 PM

    Thanks for the responses. I was running a script which needs to look into the logs for errors. I between i was doing some VI operations in specific intervals. So i wanted to check the logs in between the time intervals.

    now i am taking the get-date command output to a variable and passing the same to -Start and -Finish parameters and it works. thanks again for the responses.

    I would like to know one more thing which can be used in Get-VIEvent command. I am running like this.

    Get-VIEvent -Type Error -Start <datetime> -Finish <datetime>

    out of this how to grep for a particular string. i know there is an option called "findstr" . can you please mention how to use this findstr option?

    Thank you all !

    - Krishnaprasad



  • 7.  RE: Get-VIEvent command line options
    Best Answer

    Posted Dec 07, 2008 04:23 PM

    out of this how to grep for a particular string. i know there is an option called "findstr" . can you please mention how to use this findstr option?

    There's a few (dozen) different ways to tackle this in PowerShell. I hope these examples help:

    PS > $a = Get-VIEvent
    PS > $a | group { $_.GetType().BaseType }
    
    Count Name                      Group
    ----- ----                      -----
       20 VimApi.AlarmEvent         {13875, 13874, 13873, 13872, 13853, 13852, 13846, 13845, 13809...
        8 VimApi.SessionEvent       {13871, 13870, 13869, 13823, 13816, 13815, 13813, 13812}
       65 VimApi.VmEvent            {13868, 13867, 13866, 13865, 13864, 13863, 13862, 13861, 13860...
        2 VimApi.HostEvent          {13821, 13819}
        3 VimApi.Event              {13820, 13818, 13784}
        1 VimApi.GeneralEvent       {13817}
        1 VimApi.CustomFieldDefE... {com.icomasoft.PowerScripter.script}
    
    
    PS > $a | Where-Object { $_.key -eq 13875 }
    
    
    source               : VimApi.ManagedEntityEventArgument
    entity               : VimApi.ManagedEntityEventArgument
    from                 : gray
    to                   : green
    alarm                : VimApi.AlarmEventArgument
    key                  : 13875
    chainId              : 13845
    createdTime          : 12/7/2008 11:17:27 AM
    userName             :
    datacenter           : VimApi.DatacenterEventArgument
    computeResource      : VimApi.ComputeResourceEventArgument
    host                 : VimApi.HostEventArgument
    vm                   : VimApi.VmEventArgument
    fullFormattedMessage : Alarm Virtual Machine Memory Usage on openfiler changed from Gray to Green
    dynamicType          :
    dynamicProperty      :
    PS > $a | ? { $_.fullFormattedMessage -match "memory" } | select -first 5 | ft key, full* -auto
    
      key fullFormattedMessage
      --- --------------------
    13875 Alarm Virtual Machine Memory Usage on openfiler changed from Gray to Green
    13873 Alarm Virtual Machine Memory Usage on vcenter.halr9000.com changed from Gray to Green
    13853 Alarm Virtual Machine Memory Usage on vcenter.halr9000.com changed from Green to Gray
    13846 Alarm Virtual Machine Memory Usage on openfiler changed from Green to Gray
    13809 Alarm Virtual Machine Memory Usage on openfiler changed from Gray to Green






    [PowerShell MVP|https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], VI Toolkit forum moderator

    Author of the upcoming book: Managing VMware Infrastructure with PowerShell

    Co-Host, PowerScripting Podcast (http://powerscripting.net)

    Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org