# Variables $color = "yellow" $maxResults = 10 $searchString = Read-Host "Search for string" # Connect and get available log files If ($DefaultVIServer -eq $null) { $Server = Connect-VIServer (Read-Host "Server") $pleaseDisconnect = $True } $myLogs = @() Get-LogType | % { $myLogs += $_.Key } # Get log contents and search for matches Write-Host "________________________" ForEach ($Log in $myLogs) { $Result = (Get-Log $Log).Entries | Select-String -Pattern $searchString # Display results If (!$Result) { Write-Host "No results for $searchString in $Log log." -ForegroundColor $color Write-Host "________________________" } Else { $numResults = ($Result | Measure-Object).Count Write-Host "$numResults results found in $Log log." -ForegroundColor $color If ($numResults -gt $maxResults) { Write-Host "Displaying most recent $maxResults." -ForegroundColor $color $Result | Select -Last $maxResults Write-Host "________________________" } Else { $Result Write-Host "________________________" } } } # Disconnect from server If ($PleaseDisconnect) { Disconnect-VIServer -Confirm:$False }