We help IT Professionals succeed at work.

Powershell select-string

Robert Pollick
on
When attempting to pull all lines with, ('WilsonK21','integrate','119995
[code]

Open in new window

[/code],*'), in the same line. My results are only pulling all lines with WilsonK21.

String example below:
2020/01/27 17:04:11 pid 9464 WilsonK21@20.Q2.NSI_1_PIR82850.L xx.xxx.xxx.xxx [Helix P4V/NTX64/2019.2/1856742/v86] 'user-integrate -n //depot/MMMMM/CCC_LLLLLLL/DEVBox/LLLLLL_PPPPPPP_MMMM/...@119995,@119995 //depot/MMMMM/CCC_LLLLLLL/DEVBox/LLLLLL_PPPPPPP_MMMM/...'

$LogContent = Get-Content -Path "C:\Temp\Verify_Integrations\Resource_Files\Kelly_Integration_Main_To_Libert_INT_Helix_Log.txt"
$LogContent | Select-String -Pattern ('WilsonK21','integrate','119995') | select line | Out-File C:\Temp\Verify_Integrations\TestOutPut.txt -Width 350 -Encoding ascii

Open in new window

Comment
Watch Question

Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
Please clarify all lines with, ('WilsonK21','integrate','119995
Do you want all lines with any of these strings, or with all of them? The former works just fine.
Please provide some sample lines that were not found, even though you expected them to be.
Top Expert 2014
Commented:
I believe this is what you're after.  It would only match lines where all are present.
$LogContent | Where-Object { $_ -match 'WilsonK21' -and $_ -match 'integrate' -and $_ -match '119995' } |
 Out-File C:\Temp\Verify_Integrations\TestOutPut.txt -Width 350 -Encoding ascii

Open in new window


If you wanted lines where any of the strings was present, then you could change the "-and" operators to "-or", or use a single regex pattern like
"WilsonK21|integrate|119995"
Robert PollickConfiguration Manager

Author

Commented:
Thank you. Exactly what I was looking for.