Hi Shimon,
Please try this
Get-Mailbox | Select-Object Name,legacyExchangeDN | Export-Csv C:\legacydn.csv
Thanks, MAS
Please mark as helpful if you find my comment helpful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you.