This PowerShell code selects the correct value for var5 from this string. The desired result it \"Alert Raised\".
var5
PS C:\\src\\t> $s = \'Statu
You don't need the for loop in the batch file.
for
@ECHO OFF SET "S=Status 58 var5=Alert Raised on: March" powershell -NoLogo -NoProfile -Command " '%S%' | Where-Object { $_ -match '.*var5=(.*)\s+\w+:' } | ForEach-Object { $Matches[1] } "
The above gives the expected result.