Traitée event log failed logins

  • vendredi 9 mars 2012 09:29
     
      A du code

    Hi,

    I wrote my first powershel script today to extract failed logins for a particular database on one of our servers.

    $startdate = (Get-Date).AddDays(-31)
    $enddate = (Get-Date -f yyyy-MM-dd)
    $out_file = "\\sharepoint\DavWWWRoot\IT\\Access Login Failures\Failed_Logins_" + $enddate + ".csv" 
    Get-EventLog Application -Computer DB01 -After $startdate  |where{$_.Message -like "*Password*" -and $_.Message -notlike "*A'. *" }|where{$_.EventId -eq "18456"}|select username,message,timegenerated | export-csv $out_file -force 

    It works well and extracts the two fields I need. Although I want to improve it by making it select only the username from the Eventlog 'message'  column. The username is surrounded by two apostrophies e.g. 'USERNAME'.  

    Is this possible?



    • Modifié nick9one1 vendredi 9 mars 2012 09:31
    • Modifié nick9one1 vendredi 9 mars 2012 09:37
    •  

Toutes les réponses

  • vendredi 9 mars 2012 10:13
     
     Traitée A du code

    Hi,

    Not tested but should works: @{l="username";e={$_.message -match "'.+'" | out-null; $matches[0]}}

    Get-EventLog Application -Computer DB01 -After $startdate | where{$_.Message -like "*Password*" -and $_.Message -notlike "*A'. *" -and $_.EventId -eq "18456"} | select @{l="username";e={$_.message -match "'.+'" | out-null; $matches[0]}},message,timegenerated | export-csv $out_file -force