I am looking through logfiles for which client holds an application session. This isn't logged clearly, so you have to first find the client number getting updates, then check the log again for which client was assigned the number.
I cannot complete this last step, when I include my found number in my match, or select-string I get not hits. Writing it plainly works.
Here's my process:
$path1 = "\\path\previous\logfile\.log.1"
$path2 = "\\path\current\logfile\*.log"
$getLogContent = Get-Content $path1, $path2
$stringToSplit =$getlogcontent.where({$_ -match "Sending device updates to client"}, 'Last')
$client= $stringtosplit.split("#")
$clientString = $client[1]
$number= $clientstring.split(":")
$finalSearch = "got client ID $number"
$SessionOwner= $getlogcontent | Select-String $finalSearch -Context 3,0
$sessionOwner
Here is my data:
PS:>$stringToSplit
2020-09-18 12:24:50,042 DEBUG P0000 [ApplicationSrv] [ApplicationFactory] Sending device updates to client #122:
What I'm trying to match against:
PS:>$SessionOwner= $getlogcontent.where({$_ -match "got client ID"})
$SessionOwner
2020-09-18 06:54:56,914 INFO P0000 Application[Client 115 ] registered successfully, got client ID 115.
2020-09-18 06:58:05,109 INFO P0000 Application[Client 116 ] registered successfully, got client ID 116.
2020-09-18 07:00:04,013 INFO P0000 Application[Client 117 ] registered successfully, got client ID 117.
2020-09-18 07:06:37,101 INFO P0000 Application[Client 118 ] registered successfully, got client ID 118.
2020-09-18 07:06:43,081 INFO P0000 Application[Client 119 ] registered successfully, got client ID 119.
2020-09-18 07:11:19,963 INFO P0000 Application[Client 120 ] registered successfully, got client ID 120.
2020-09-18 10:20:26,638 INFO P0000 Application[Client 121 ] registered successfully, got client ID 121.
2020-09-18 10:43:57,085 INFO P0000 Application[Client 122 ] registered successfully, got client ID 122.
2020-09-18 10:59:21,873 INFO P0000 Application[Client 123 ] registered successfully, got client ID 123.
2020-09-18 11:23:31,339 INFO P0000 Application[Client 124 ] registered successfully, got client ID 124.
2020-09-18 11:41:13,406 INFO P0000 Application[Client 125 ] registered successfully, got client ID 125.
2020-09-18 12:14:23,370 INFO P0000 Application[Client 126 ] registered successfully, got client ID 126.
I feel I've tried all kinds of joins, regex'es, "search text $varaible"
, 'search text'$variable
and making a new complete $variable
. I'm completely stumped as to how I can add the $number
to my string and search for it.