Configuring existing PowerShell script to export the data as .CSV from Get-EventLog ?

Hi All,

I need some help in modifying the existing PowerShell script that is parsing all domain controllers for specific Event ID: 4625 and 4624.

Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=8192))" | ForEach-Object { "Processing $($_.DNSHostName) ..." | Write-Host Get-Eventlog -logname "Security" -ComputerName $_.Name | where {($_.eventID -eq 4624) -or ($_.eventID -eq 4625) } | select timegenerated,message | ft -Wrap }

The script above is working, but there is no way to export it to .CSV file with the below column:

DomainController, Time generated, Account Name, Workstation Name, Logon Type

To execute the script, I usually use the PowerShell ISE on the Domain Controllers Run as Administrator under the Enterprise Admins credentials to work.

Any help would be greatly appreciated.

Thanks in advance.