我有以下命令:
Get-WinEvent -FilterHashtable @{
Logname = 'Application'
ID = 1000
ProviderName = 'Application Error'
} -MaxEvents 1 | select TimeCreated
我得到以下输出:
TimeCreated ----------- 04-Jan-16 11:29:11 PM
我希望将此值保存到变量中并添加两个小时,如下所示:
$ErrorTime = Get-WinEvent -FilterHashtable @{
Logname = 'Application'
ID = 1000
ProviderName = 'Application Error'
} -MaxEvents 1 | select TimeCreated
$Time1 = ($ErrorTime).AddHours(2)
但是做到这一点并没有给我想要的答案。它不会将时间存储为值。
答案 0 :(得分:1)
您需要展开事件对象的TimeCreated
属性才能获得DateTime
值:
$ErrorTime = Get-WinEvent -FilterHashtable @{
Logname = 'Application'
ID = 1000
ProviderName = 'Application Error'
} -MaxEvents 1 | Select-Object -Expand TimeCreated
$Time1 = $ErrorTime.AddHours(2)
您可以通过对象的Date
和Time
属性获取时间戳的日期和时间部分:
$date = $Time1.Date
$time = $Time1.Time