Get Mailbox Details

Getting mailbox details are a mundane task for admins. The below script will provide you with general mailbox details that may required

UserID, UserAlias, UserDisplayName, UserType, UserUPN ,UserEmail (Only Primary SMTP) and Mailbox Size.

$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('dd-MM-yyyy_HH-mm-ss')

$report = @()
$i = 0

$Mailboxes = Get-mailbox -ResultSize Unlimited | Select-Object Identity, Alias, DisplayName, RecipientTypeDetails, UserPrincipalName, PrimarySmtpAddress

Foreach ($Mailbox in $Mailboxes)
{
   $UserID = $Mailbox.Identity
   $UserAlias = $Mailbox.Alias
   $UserDisplayName = $Mailbox.DisplayName
   $UserType = $Mailbox.RecipientTypeDetails
   $UserUPN = $Mailbox.UserPrincipalName
   $UserEmail = $Mailbox.PrimarySmtpAddress

   Write-Host "Email: "$UserEmail

   $MailboxStat = Get-MailboxStatistics -Identity $UserEmail | Select-Object TotalItemsize

   $MailboxSize = $MailboxStat.TotalItemsize


   $userObj = New-Object PSObject
   $userObj | Add-Member NoteProperty -Name "Identity" -Value $UserID
   $userObj | Add-Member NoteProperty -Name "Alias" -Value $UserAlias
   $userObj | Add-Member NoteProperty -Name "DisplayName" -Value $UserDisplayName
   $userObj | Add-Member NoteProperty -Name "RecipientTypeDetails" -Value $UserType
   $userObj | Add-Member NoteProperty -Name "UserPrincipalName" -Value $UserUPN
   $userObj | Add-Member NoteProperty -Name "WindowsEmailAddress" -Value $UserEmail
   $userObj | Add-Member NoteProperty -Name "Mailbox Size" -Value $MailboxSize

   $report = $report += $userObj
   $ii++
}

$report

Published by iamfazul

Author of the site

Leave a comment