I am searching for the string below in a .txt log file, but it outputs extra information. I read that PSv7 solved this issue with the -Raw parameter, but I am still getting extra information. When running PSv5, I would get the path in addition to the below, but now the -Raw has eliminated the path, but kept some other information from the same line the string is on.
What I am looking for:
An error occurred stopping transcription
What I get:
<![LOG[Stop-Transcript : An error occurred stopping transcription: The host is not currently transcribing.]LOG]!><time="17:02:46.072 300" date="12-10-2021" component="RunPowerShellScript" context="" type="3" thread="8436" file="main.cpp:76">
The subset of my code:
Select-String -Path C:\somepath\log.txt -SimpleMatch "An error occurred stopping transcription" -Raw
I am try to follow up with a:
if ($errorcode -match $retrieveError) {
But, I can't match without the string matching the output.
Ugh
CodePudding user response:
@AdminofThings answered below. It is:
(Select-String -Path $logfiledest -SimpleMatch $errorcode).Pattern
