Exporting Windows AD Logs (user_context & asset_context) - NXLog Issue

I'm configuring a PowerShell script and Task Scheduler to export Windows AD logs (user_context & asset_context) to a TXT or CSV file. I'm attempting to read this with NXLog but haven't had success.

Has anyone else encountered this issue?
Are there alternative methods or best practices to consider for exporting and centralizing these AD logs?

2 1 297
1 REPLY 1

Change directory and file name;

# Set the location where the log file will be written
$OUTPUT_DIRECTORY = "Your directory"
$OUTPUT_FILENAME = "filepath"
$OUTPUT_PATH = Join-Path -Path $OUTPUT_DIRECTORY -ChildPath $OUTPUT_FILENAME

# Remove the existing output file if it exists
If (Test-Path -Path $OUTPUT_PATH) { Remove-Item -Path $OUTPUT_FILENAME -ErrorAction SilentlyContinue }

# USER_CONTEXT: Gets all Active Directory users and their properties.
Get-ADUser -Filter * -properties samAccountName | % { Get-ADUser $_.SamAccountName -properties * | ConvertTo-JSON -compress | Out-File -encoding utf8 $OUTPUT_PATH -Append }

# ASSET_CONTEXT: Gets all Active Directory assets and their properties.
Get-ADComputer -Filter * -properties samAccountName | % { Get-ADComputer $_.SamAccountName -properties * | ConvertTo-JSON -compress | Out-File -encoding utf8 $OUTPUT_PATH -Append }