I am trying to search a .eml file for all emails and add <> brackets between each email found, here's the code I have, it outputs what should happen but it does not write to the file. Note, I need to keep the existing data in the file (Title, body,etc.), only replacing the email address.
$rawtext = [IO.File]::ReadAllText("c:\scripts\emailex.eml")
$regex = [regex]"(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"
$regex.Matches($rawtext) | ForEach-Object{ $_ -replace $($_.Value), "<$_>" }