VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

get-log

hi luc ,

could you sugest what is wrong in following .i have connected to $esxi_name .

get-log -VMHost $esxi_name -key vmkernel | ?{$_.Entries | ?{$_ -contains "2018-10-04"}}

iam not getting any output .i was expecting all vmkernel logs for "2018-10-04"

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Log -VMHost $esxi_name -key vmkernel | Select -ExpandProperty Entries | where{$_ -match "2018-10-04"}


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

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Log -VMHost $esxi_name -key vmkernel | Select -ExpandProperty Entries | where{$_ -match "2018-10-04"}


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

will conditional operator -match is the right use to get logs for "2018-10-04"  as it can match for partial "2018-10-".

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, with -match you can look for a substring in a string


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

could you please check the following code and suggest how i can pass multiple values against orange line.so that i can filter logs as per multiple values.

below woks fine if i put 2018-10-04 only or any single string.

$cred = Get-Credential

#connect-viserver -Server $vcenter -Credential $cred | Out-Null

$esxi_name=Read-Host "what esxi"

connect-viserver -Server $esxi_name  -Credential $cred | Out-Null

$logs_type=read-host "what logs " "choices are " "fdm/hostd/vmkernel/vpxa"

$match=read-host "what string or array to be checked?  like latency,error,warning,date,etc...."

get-log -key $logs_type | Select -ExpandProperty Entries | where{$_ -match "$match"}|out-file $esxi_name-vmkernellog.txt

#Get-Log -Key $logs | ?{$_.Entries | where{$_ -match "$match" -or "$match1"}}|

#out-file logs_$logs.txt

notepad $esxi_name-vmkernellog.txt

Disconnect-VIServer "*" -Confirm:$false

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The -match operator expects a RegEx on the right side.

And with RegEx you can match against multiple patterns (by using an 'or', symbol is |, between them).

For example

$match = "string1|string2|string3"

The -match will check if 'string1' or 'string2' or 'string3' are matched.


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

i did following

pastedImage_0.png

and  since it is or it has taken logs before 04 oct also .which i dont want .

i need "and "

one  way iam thinking to repeat line for match but i think its not efficient way of passing multiple values .

$cred = Get-Credential

$esxi_name=Read-Host "what esxi"

connect-viserver -Server $esxi_name  -Credential $cred | Out-Null

$logs_type=read-host "what logs " "choices are " "fdm/hostd/vmkernel/vpxa"

$match=read-host "what string or array to be checked?  like latency,error,warning,date,etc...."

$match1=read-host "what string or array to be checked?  like latency,error,warning,date,etc...."

get-log -key $logs_type | Select -ExpandProperty Entries | where{$_ -match "$match" -and $_ -match $match1}|out-file $esxi_name-vmkernellog.txt

notepad $esxi_name-vmkernellog.txt

Disconnect-VIServer "*" -Confirm:$false

pastedImage_2.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is one option, but you can also use the RegEx positive lookahead.

Something like this for example.
In this case the string must match 'string1' and 'string2' and 'string3'

$match = ".*(?=.*string1)(?=.*string2)(?=.*string3).*"


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

0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaks .iam checking this .is it mentioned somewhere ?? and by RegEx you mentioned regular expression?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, RegEx stands for Regular Expression.

There should be tons of information about Regular Expressions on the Internet.
This is a quite good intro https://regexone.com/


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

0 Kudos