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
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
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