简体   繁体   English

选择字符串以从日志文件条目中获取时间格式

[英]Select-string to grab time format from a log file entry

I am trying to pull date and time from the similar string below: 我试图从下面的类似字符串中提取日期和时间:

<![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">

I am using these declarations: 我正在使用以下声明:

$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

I am trying to identify in which order each of their last entries happen (based on timestamp in its string) and then I will write code accordingly. 我试图确定每个最后一个条目的出现顺序(基于其字符串中的时间戳),然后我将相应地编写代码。

You should be able to extract date and time information with something like this (assuming you have PowerShell v3 installed): 您应该能够使用以下内容提取日期和时间信息(假设您已安装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
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM