You've probably got your answer by now, but "Imma giv eya more!"
Assuming we have these defined ahead of time:
$Log = "<Stuff><Msg>Number of days since last service =18</Msg></Stuff>"
$StringHint = "Number of days since last service ="
1. Your typical Select-String method of doing things with Regexes. yep.
Select-String -InputObject $Log -Pattern "(?<=$StringHint)\d{1,}(?=<)" -AllMatches | % {$_.Matches.Groups[0].Value}
2. Doing the splits:
((($Log -split $StringHint)[1]) -split "<")[0]
3. The XML way. This only works for XML log files and if there is no other MSG tag (which is unlikely in this case).
I chose to include this because I think it's cool how a simple type cast can dramatically alter how we can work with the data. Plus, it's a really easy way of stripping the nasty <'s and >'s away.
$xml = [xml]$Log
$EqualsLoc = $xml.Stuff.Msg.IndexOf("=")
$xml.Stuff.Msg.Substring($EqualsLoc+1)
The above would have been even better if you had a log file like this (yes, I know this is a configuration file and not a log file):
$XML = [xml]"<Application>
<version>1.3.53</version>
<AdvancedSettings>
<Network>
<InternetForWeebs>False</InternetForWeebs>
<HackAllTheSystems>True</HackAllTheSystems>
<L33tHandle>Gingervitis</L33tHandle>
</Network>
</AdvancedSettings>
<BasicSettings>
<Controls>
<TheAnyKeyDesignation>0x42</TheAnyKeyDesignation>
<CanHazCheeseburgerMode>True</CanHazCheeseburgerMode>
</Controls>
</BasicSettings>
<Diagnostics>
<DaysSinceLastService>18</DaysSinceLastService>
</Diagnostics>
</Application>"
Then, getting the entry you needed would be something as easy as this:
$XML.Application.Diagnostics.DaysSinceLastService
:facepalm: