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"
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
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
will conditional operator -match is the right use to get logs for "2018-10-04" as it can match for partial "2018-10-".
Yes, with -match you can look for a substring in a string
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
i did following
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
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
thnaks .iam checking this .is it mentioned somewhere ?? and by RegEx you mentioned regular expression?
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