I have a simple executable that runs, returns a few lines of code.
I need to grab a section of hex out of that line and store it in a variable.
I have something that works, but would like to make it cleaner? or one line?
The output is several lines, I only care about the one with the hex code. Typical return string
Info: Download of filename (0xff77) completed
$test1 = .\some.exe 2>&1 | Select-String -Pattern "0x"
$test1 -match "[0-9a-fA-F]{4}"
$test1 = $Matches[0]
I tried piping the output of the first line like so
$test1 = .\some.exe 2>&1 | Select-String -Pattern "0x" | -match "[0-9a-fA-F]{4}"
Obviously that didnt work, and I cant find much else on a better way to do this.
Is there a way to address the result of the previous pipeline to pass it to the match command?
$test1 = .\some.exe 2>&1 | Select-String -Pattern "0x" | $HiddenPrevPipeVar -match "[0-9a-fA-F]{4}"
What I want my $test1 to be equal to is the hex code ff77