I have a script that looks for through the Security Events 4624 and 4634 for a single user.<\/p>\n
It runs without any problem however it isn’t showing it as logon or Logoff event.<\/p>\n
Is there any way of adding the Event ID to the end of the “write-host” relating to it’s ID in the Security Event Log?<\/p>\n
The PowerShell script which runs without any issue can be seen below<\/p>\n
$checkuser=‘username<\/em>’<\/p>\n $startDate = (get-date).AddDays(-14) if ($event.ReplacementStrings[8] -eq 3){ I have a script that looks for through the Security Events 4624 and 4634 for a single user.<\/p>\n It runs without any problem however it isn’t showing it as logon or Logoff event.<\/p>\n Is there any way of adding the Event ID to the end of the “write-host” relating to it’s ID in the Security Event Log?<\/p>\n The PowerShell script which runs without any issue can be seen below<\/p>\n $checkuser=‘username<\/em>’<\/p>\n $startDate = (get-date).AddDays(-14) if ($event.ReplacementStrings[8] -eq 3){ If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n<\/a>getting information about the user logon history for the last 14 days (you can change this value)<\/h1>\n
\n$DCs = Get-ADDomainController -Filter *
\nforeach ($DC in $DCs){
\n$slogonevents = Get-Eventlog -LogName Security -ComputerName $DC.Hostname -after $startDate | where {($.eventID -eq 4624) -or ($<\/em>.eventID -eq 4634)
\nforeach ($event in $logonevents){
\nif (($event.ReplacementStrings[5] -notlike ‘*$’) -and ($event.ReplacementStrings[5] -like $checkuser)) {<\/p>\n<\/a>Network(Logon Type 3)<\/h1>\n
\nwrite-host \"Type 3: Network LogontDate: \"$event.TimeGenerated \"<\/code>tStatus: Success
tUser: \"$event.ReplacementStrings[5] \"<\/code>tWorkstation: \"$event.ReplacementStrings[11] \"
tIP Address: \"$event.ReplacementStrings[18] \"<\/code>tDC Name: \" $dc.Name
\n}
\n}
\n}
\n}
\n}<\/p>","upvoteCount":9,"answerCount":9,"datePublished":"2024-01-02T15:29:59.000Z","author":{"@type":"Person","name":"michaelcoulter","url":"https://community.spiceworks.com/u/michaelcoulter"},"suggestedAnswer":[{"@type":"Answer","text":"<\/a>a username, whose logon history you want to view<\/h1>\n
<\/a>getting information about the user logon history for the last 14 days (you can change this value)<\/h1>\n
\n$DCs = Get-ADDomainController -Filter *
\nforeach ($DC in $DCs){
\n$slogonevents = Get-Eventlog -LogName Security -ComputerName $DC.Hostname -after $startDate | where {($.eventID -eq 4624) -or ($<\/em>.eventID -eq 4634)
\nforeach ($event in $logonevents){
\nif (($event.ReplacementStrings[5] -notlike ‘*$’) -and ($event.ReplacementStrings[5] -like $checkuser)) {<\/p>\n<\/a>Network(Logon Type 3)<\/h1>\n
\nwrite-host \"Type 3: Network LogontDate: \"$event.TimeGenerated \"<\/code>tStatus: Success
tUser: \"$event.ReplacementStrings[5] \"<\/code>tWorkstation: \"$event.ReplacementStrings[11] \"
tIP Address: \"$event.ReplacementStrings[18] \"<\/code>tDC Name: \" $dc.Name
\n}
\n}
\n}
\n}
\n}<\/p>","upvoteCount":9,"datePublished":"2024-01-02T15:29:59.000Z","url":"https://community.spiceworks.com/t/pulling-logon-and-logoff-instormation-from-ad/964615/1","author":{"@type":"Person","name":"michaelcoulter","url":"https://community.spiceworks.com/u/michaelcoulter"}},{"@type":"Answer","text":"<\/p>\n