I have some Powershell that works with mail from Outlook folders. There is a footer on most emails starting with text "------"
. I want to dump all text after this string.
I have added an expression to Select-Object
as follows:
$cleanser = {($_.Body).Substring(0, ($_.Body).IndexOf("------"))}
$someObj | Select-Object -Property @{ Name = 'Body'; Expression = $cleanser}
This works when the IndexOf()
returns a match... but when there is no match my Select-Object
outputs null
.
How can I update my expression to return the original string when IndexOf
returns null
?