【发布时间】:2020-09-18 15:19:53
【问题描述】:
我正在查看客户端持有应用程序会话的日志文件。 这没有清楚地记录,因此您必须首先找到正在更新的客户编号,然后再次检查为哪个客户分配了该编号的日志。
当我在匹配项中包含我找到的号码或选择字符串时,我无法完成这最后一步。写出来很简单。
这是我的过程:
$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
这是我的数据:
PS:>$stringToSplit
2020-09-18 12:24:50,042 DEBUG P0000 [ApplicationSrv] [ApplicationFactory] Sending device updates to client #122:
我要匹配的对象:
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.
我觉得我已经尝试了各种连接、正则表达式、"search text $varaible"、'search text'$variable 并制作了一个新的完整 $variable。我完全不知道如何将$number 添加到我的字符串中并进行搜索。
【问题讨论】:
标签: string-matching powershell-5.0