使用 Where-Object 在 Windows Server 2003 上按日期过滤 Get-WmiObject
Filtering Get-WmiObject by date on Windows Server 2003 with Where-Object
我正在尝试按日期过滤此查询(获取 $time 之后的值)。我没有在 -filter 参数中执行此操作,因为我在 Windows Server 2003 SP2 上遇到错误。
$colLogFiles = Get-WmiObject -Class Win32_NTLogEvent -ComputerName "localhost" | Where-Object {($_.EventType -eq "1") -or (($_.EventType -eq "2") -and ($_.TimeGenerated -gt $time))}
但是最后一个条件它没有做任何事情,我认为这是因为日期时间格式没有被识别。 $_.TimeGenerated 的一个例子是 20181213144843.186997-000
是否有任何方法可以执行此操作或更改日期时间格式?
我用库 win32com 在 Python 中解决了这个问题。然后我用这个日期格式给它添加一个过滤器!
time = datetime.today() + timedelta(hours=5, minutes=-10)
timeFormatted = time.strftime("%Y%m%d%H%M%S.000000-000")
系统 wmi 格式有一个 GTM 0,但我的电脑是 GTM -5,这就是我增加 5 小时的原因。
查询:
query = "Select * from Win32_NTLogEvent where (EventType = 1 or EventType = 2) and TimeGenerated >= " + "\"" + timeFormatted + "\""
2003 太有限了!
谢谢大家
我正在尝试按日期过滤此查询(获取 $time 之后的值)。我没有在 -filter 参数中执行此操作,因为我在 Windows Server 2003 SP2 上遇到错误。
$colLogFiles = Get-WmiObject -Class Win32_NTLogEvent -ComputerName "localhost" | Where-Object {($_.EventType -eq "1") -or (($_.EventType -eq "2") -and ($_.TimeGenerated -gt $time))}
但是最后一个条件它没有做任何事情,我认为这是因为日期时间格式没有被识别。 $_.TimeGenerated 的一个例子是 20181213144843.186997-000
是否有任何方法可以执行此操作或更改日期时间格式?
我用库 win32com 在 Python 中解决了这个问题。然后我用这个日期格式给它添加一个过滤器!
time = datetime.today() + timedelta(hours=5, minutes=-10)
timeFormatted = time.strftime("%Y%m%d%H%M%S.000000-000")
系统 wmi 格式有一个 GTM 0,但我的电脑是 GTM -5,这就是我增加 5 小时的原因。
查询:
query = "Select * from Win32_NTLogEvent where (EventType = 1 or EventType = 2) and TimeGenerated >= " + "\"" + timeFormatted + "\""
2003 太有限了!
谢谢大家