我正在尝试从下面的类似字符串中提取日期和时间:
<![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:windirsyswow64ccmlogsinventoryagent.log -pattern "SinvEndpoint" -SimpleMatch | select-object -last 1
$Hinv = Select-String $env:windirsyswow64ccmlogsinventoryagent.log -pattern "HinvEndpoint" -SimpleMatch | select-object -last 1
$DDR = Select-String $env:windirsyswow64ccmlogsinventoryagent.log -pattern "DdrEndpoint" -SimpleMatch | select-object -last 1
我正在尝试确定每个最后条目发生的顺序(基于其字符串中的时间戳),然后我将相应地编写代码。
你应该能够使用如下内容提取日期和时间信息(假设你安装了PowerShell v3):
$file = "$env:windirsyswow64ccmlogsinventoryagent.log"
$pattern = 'SinvEndpoint.*<time="(.*?)" date="(.*?)"'
$Sinv = Select-String $pattern $file | select -Last 1 | % {
$_.Matches.Groups[2].Value + ' ' + $_.Matches.Groups[1].Value
}