如何仅输出TimeStamp大于特定时间的对象? 我试图比较每个日期时间。 例如,仅输出小于1 AM但大于12 AM的行?将字符串转换为Powershell中的日期时间
2016-04-06 12:02:32 AM - INFO – Connected to services 2016-04-06 12:02:47 AM - ERROR – Service exception System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Pooled connection request timed out (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: Oracle.ManagedDataAccess.Client.OracleException: Pooled connection request timed out at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch) at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch) at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword) at Oracle.ManagedDataAccess.Client.OracleConnection.Open() 2016-04-06 12:02:47 AM - WARN – Unexpected error has occurred. See application logs for more details. Service will wait for 60 seconds and then try again. 2016-04-06 12:07:07 AM - INFO – Connected to services 2016-04-06 12:07:22 AM - ERROR – Service exception System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: Pooled connection request timed out (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: Oracle.ManagedDataAccess.Client.OracleException: Pooled connection request timed out at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch) at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch) at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword) at Oracle.ManagedDataAccess.Client.OracleConnection.Open() 2016-04-06 12:07:22 AM - WARN – Unexpected error has occurred. See application logs for more details. Service will wait for 60 seconds and then try again.
我试图用ParseExact到日期时间转换,但我得到了以下错误:
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid
DateTime."
At line:18 char:9
+ $Translate = [DateTime]::ParseExact($item.TimeStamp, $Format, $null)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
这是我目前有:
$content = Get-Content "Path to log"
$array = @()
$regex = '(?si)(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s\w{2})\s-\s(\w+)\s+–\s(.+?)(?=\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s\w{2}\s-\s|$)'
$entries = [regex]::Matches($content, $regex)
foreach ($entry in $entries)
{
$array += [PSCustomObject]@{
TimeStamp = $entry.Groups[1].Value
Level = $entry.Groups[2].Value
Message = $entry.Groups[3].Value
}
}
$array | FT -AutoSize
$Format = "yyyy-MM-dd HH:mm:ss tt"
ForEach ($item in $array)
{
Foreach ($time in $item.TimeStamp)
{
$Translate = [DateTime]::ParseExact($item.TimeStamp, $Format, $null)
$Translate.ToString()
}
}
虽然我试图比较每个时间戳与特定时间。出于某种原因,它不是那样做的。 – SumoStash
'Get-Date'返回'DateTime'对象。你可以比较'DateTime'对象。 –