I am trying to export all the mailbox in our environment with the following field.
Name
DisplayName
SamAccountName
EmailAddresses
PrimarySmtpAddress
Database
TotalItemSize
ItemCount
Can anyone please check if the below script is correct or not?
$report = @() $Mbxs = Get-Mailbox -resultsize unlimited foreach ($Mbx in $Mbxs) { $TotalItemSize = (Get-MailboxStatistics $Mbx).TotalItemSize $ItemCount = (Get-MailboxStatistics $Mbx).ItemCount $reportObj = New-Object PSObject $reportObj | Add-Member NoteProperty -Name "Name" -Value $mbx.Name $reportObj | Add-Member NoteProperty -Name "DisplayName" -Value $mbx.DisplayName $reportObj | Add-Member NoteProperty -Name "SamAccountName" -Value $mbx.SamAccountName $reportObj | Add-Member NoteProperty -Name "EmailAddresses" -Value $mbx.EmailAddresses $reportObj | Add-Member NoteProperty -Name "PrimarySmtpAddress" -Value $mbx.PrimarySmtpAddress $reportObj | Add-Member NoteProperty -Name "Database" -Value $mbx.Database $reportObj | Add-Member NoteProperty -Name "TotalItemSize" -Value $TotalItemSize $reportObj | Add-Member NoteProperty -Name "ItemCount" -Value $ItemCount $report += $reportObj }