$x = '(ART)End Processing Autoroutines (12/06/15 15:50:47)'
New-TimeSpan -Start (Get-Date) -End ($x.Split('(',3)[-1]).TrimEnd(')')
I have no idea of your skill level, so it’s possible this might hurt your brain. In case it does, then let’s walk though how I came up with this.
- I assigned $x the string you’re collecting from your log file.
PS C:\> $x = '(ART)End Processing Autoroutines (12/06/15 15:50:47)'
- I wanted to start splitting up the string, and did so at the left parens. I indicated to the .Split() method to make three substrings, so I could get the date and time on a line by itself. For fun, try changing 3, to 1 and 2 to see the difference.
PS C:\> $x.Split('(',3)
ART)End Processing Autoroutines
- Next, I grabbed the last element, or index, so it would only give me the last substring.
PS C:\> $x.Split('(',3)[-1]
- When I just had the date and time, I used the .TrimEnd() method to remove the ending right paren.
PS C:\> ($x.Split('(',3)[-1]).TrimEnd(')')
- In the end, I stuffed all this together as the value for the New-TimeSpan’s -End parameter and it returned the comparison.
Edit: Or just use Dave’s suggestion. By the way, all those double quotes are supposed to be single. I’m not sure why that happened.