0

我正在尝试从下面的类似字符串中提取日期和时间:

<![LOG[Inventory: Successfully sent report. Destination:mp:MP_SinvEndpoint, ID: {CFF6CD46-AEC7-4BFB-8B09-E7507346AAF6}, Timeout: 80640 minutes MsgMode: Signed, Not Encrypted]LOG]!><time="14:30:50.088+300" date="09-24-2013" component="InventoryAgent" context="" type="1" thread="4448" file="agentstate.cpp:2038">

我正在使用这些声明:

$Sinv = Select-String $env:windir\syswow64\ccm\logs\inventoryagent.log -pattern "SinvEndpoint" -SimpleMatch | select-object -last 1

$Hinv = Select-String $env:windir\syswow64\ccm\logs\inventoryagent.log -pattern "HinvEndpoint" -SimpleMatch | select-object -last 1

$DDR = Select-String $env:windir\syswow64\ccm\logs\inventoryagent.log -pattern "DdrEndpoint" -SimpleMatch | select-object -last 1

我试图确定每个最后一个条目的发生顺序(基于其字符串中的时间戳),然后我将相应地编写代码。

4

1 回答 1

0

您应该能够使用以下方式提取日期和时间信息(假设您安装了 PowerShell v3):

$file    = "$env:windir\syswow64\ccm\logs\inventoryagent.log"
$pattern = 'SinvEndpoint.*<time="(.*?)" date="(.*?)"'

$Sinv = Select-String $pattern $file | select -Last 1 | % {
          $_.Matches.Groups[2].Value + ' ' + $_.Matches.Groups[1].Value
        }
于 2013-09-25T19:43:56.907 回答