I’ve been working with Exchange some more, lately, where I’ve also had to generate an overview of the mailboxes, mailbox-types and if the underlying account is enabled or not. This had to be exported to a CSV-file. I came to the next lines of code for that:

$AllMailboxes = Get-Mailbox
$AllMailboxes | select Name,PrimarySmtpAddress,DistinguishedName,OrganizationalUnit,RecipientTypeDetails,@{Name="AccountEnabled";Expression={(Get-ADUser $_.DistinguishedName).Enabled}} | Export-Csv "~\Documents\AllMailboxes_$((Get-Date).ToString("yyyyMMdd_HHmm")).csv" -Delimiter ";" -NoTypeInformation