代码之家  ›  专栏  ›  技术社区  ›  ShadowM82

分析PowerShell中的PSCustomObject,事件日志

  •  0
  • ShadowM82  · 技术社区  · 12 年前

    所以我需要一些帮助。我参与了一个项目,包括编写一个powershell脚本。我需要能够从Windows7机器的安全日志中获取最新的SuccessAudit,ID=4776。

    我设法在几个小时内完成了这项工作,这是我第一次使用powershell。

    $eventtime=Get-EventLog Security | {$_.EventId -eq 4776} | where {$_.entrytype -eq "SuccessAudit"} | Select-Object TimeGenerated | Select -first 1
    

    通过控制台输出(不设置变量):

    TimeGenerated
    --------------------------
    4/10/2013 10:35:01 PM
    

    如果我将命令设置为变量,这是变量的结果:

    @{TimeGenerated=4/10/2013 10:35:01 PM}
    

    我想减少变量,使其仅等于日期和时间: 2013年4月10日晚上10:35:01

    帮助我已经做了好几个小时了!

    1 回复  |  直到 12 年前
        1
  •  2
  •   CB.    12 年前

    尝试:

    $eventtime=Get-EventLog Security | ? {$_.EventId -eq 4776} | 
    where {$_.entrytype -eq "SuccessAudit"} | 
    Select-Object -expand TimeGenerated | Select -first 1