I'm guessing that the data you export doesn't have the properties you expected? See if this works better:
$DomainName = (Get-ADDomain).DNSRoot
(Get-ADDomainController -Filter * -Server $DomainName).HostName |
ForEach-Object{
$DC = $_
Try{
Get-Winevent -FilterHashtable @{Logname='System';ID=5829,5830} -MaxEvents 1 -ComputerName $DC |
Select-Object MachineName,ID,TimeCreated,Message |
Export-Csv 529.csv -NTI
}
Catch{
$Err = $_ | Out-String
Add-Content "$DC $Err " -path c:\temp\UnreachableDCs.txt
}
}
Note that this will only get the Domain Controllers in your domain and not the entire forest. If you have a multi-domain forest you can certainly get the list of domains in the forest and for each domain get the names of all the domain controllers in each domain.