Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. Write-Host "Gathering Event Logs, this can take awhile..."
  2. #fuction logon
  3. $ELogs = Get-WinEvent -ComputerName REMOTE-COMPUTER-01 -Credential AD\T2User -LogName System
  4.  
  5. If ($ELogs)
  6. { Write-Host "Processing logon..."
  7. ForEach ($Log in $ELogs)
  8. { If ($Log.InstanceId -eq 7001)
  9. { $ET = "Logon"
  10. }
  11. ElseIf ($Log.InstanceId -eq 7002)
  12. { $ET = "Logoff"
  13. }
  14. Else
  15. { Continue
  16. }
  17. $Result += New-Object PSObject -Property @{
  18. Time = $Log.TimeWritten
  19. 'Event Type' = $ET
  20. User = (New-Object System.Security.Principal.SecurityIdentifier $Log.ReplacementStrings[1]).Translate([System.Security.Principal.NTAccount])
  21. }
  22. }
  23. #$Result | Select Time,"Event Type",User | Sort Time -Descending | Out-GridView
  24. }
  25.  
  26. $Result | Select Time,"Event Type",user| Sort Time -Descending | export-csv "C:\AMD\$Computer Logon History v1.csv" -NoTypeInformation
  27.  
  28. # Trim AD\ (in memory only) so that we can properly grab both Manager and Department attributes using Get-ADUser, and apply that to the entire User column in the .CSV
  29. Import-csv "C:\AMD\$Computer Logon History v1.csv" | select *, @{Name='Manager';Expression={(get-aduser (get-aduser ($_.User).replace('AD\','') -Properties manager).manager).samaccountName}} | select *, @{name="Department"; expression={ (get-aduser ($_.User).replace('AD\','') -Properties Department).Department } } | export-csv "C:\AMD\$Computer Logon History v2.csv" -NoTypeInformation
  30.  
  31. Write-Host "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement