# Retrieve the list of mailboxes from the specified OU $CustomerName = "Customer" $CustomerOU = "OU=$CustomerName,OU=Tenants,dc=systemeccloud,dc=nl" $listOfMailboxes = Get-Mailbox -OrganizationalUnit $CustomerOU $listOfDisabledMailboxes = Get-Mailbox -OrganizationalUnit $CustomerOU -RecipientTypeDetails UserMailbox | ?{(Get-User $_.Alias).UserAccountControl -match 'AccountDisabled'} $archiveMailboxes = Get-Mailbox -OrganizationalUnit $CustomerOU | where {$_.ArchiveDatabase -ne $null} # Retrieve and Convert date $reportTime = (Get-Date).ToString('dd/MM/yyyy HH:mm') # Set Filename $filenamedate = (Get-Date).tostring("yyyy-MM") $fileName = "C:\Mailbox Statistics\Mailbox Report $CustomerName $filenamedate.txt" New-Item -ItemType file $fileName -Force # Initialize the counter variables that we'll use $mailboxCount = 0 $mailboxArchiveCount = 0 $mailboxTotalItemCount = 0 $mailboxTotalArchiveItemCount = 0 $mailboxTotalSize = 0 $mailboxTotalArchiveSize = 0 # Mailbox # Start a loop that will count stats from individual mailboxes foreach ($individualMailbox in $listOfMailboxes) { # increment the mailbox count by 1 $mailboxCount++ # Get the name of the current mailbox so that we can... $individualMailboxName = $individualMailbox.Identity.DistinguishedName #... quickly and easily get stats from that mailbox $individualMailboxStats = Get-MailboxStatistics -Identity $individualMailbox # Get the size of the mailbox in KB and save it in a variable $individualMailboxSize = $individualMailboxStats.TotalItemSize.value.toKB() # Get the number of items in the mailbox and save it in a variable $individualMailboxItemCount = $individualMailboxStats.ItemCount # Add the size of this mailbox to a running total $mailboxTotalSize = $mailboxTotalSize + $individualMailboxSize # Add the number of items in this mailbox to a running total $mailboxTotalItemCount = $mailboxTotalItemCount + $individualMailboxItemCount } # Archive # Start a loop that will count stats from individual archive mailboxes foreach ($individualMailboxArchive in $archiveMailboxes) { # increment the mailbox archive count by 1 $mailboxArchiveCount++ # Get the name of the current mailbox so that we can... $individualMailboxArchiveName = $individualMailboxArchive.Identity.DistinguishedName #... quickly and easily get stats from that mailbox archive $individualMailboxArchiveStats = Get-MailboxStatistics -Identity $individualMailboxArchive -Archive # Get the size of the mailbox archive in KB and save it in a variable $individualMailboxArchiveSize = $individualMailboxArchiveStats.TotalItemSize.value.toKB() # Get the number of items in the archive and save it in a variable $individualMailboxArchiveItemCount = $individualMailboxArchiveStats.ItemCount # Add the size of this mailbox archive to a running total $mailboxTotalArchiveSize = $mailboxTotalArchiveSize + $individualMailboxArchiveSize # Add the number of items in this mailbox archive to a running total $mailboxTotalArchiveItemCount = $mailboxTotalArchiveItemCount + $individualMailboxArchiveItemCount } # Retrieve aditional info $Users = (Get-Mailbox -OrganizationalUnit $CustomerOU | Get-Recipient -ResultSize unlimited -ignoredefaultscope -RecipientTypeDetails 'UserMailbox').count $Shared = (Get-Mailbox -OrganizationalUnit $CustomerOU | Get-Recipient -ResultSize unlimited -ignoredefaultscope -RecipientTypeDetails 'SharedMailbox').count $Room = (Get-Mailbox -OrganizationalUnit $CustomerOU | Get-Recipient -ResultSize unlimited -ignoredefaultscope -RecipientTypeDetails 'RoomMailbox').count $Archive = (Get-Mailbox -OrganizationalUnit $CustomerOU -Archive).count $DisabledUsers = (Get-Mailbox -OrganizationalUnit $CustomerOU -RecipientTypeDetails UserMailbox | ?{(Get-User $_.Alias).UserAccountControl -match 'AccountDisabled'}).count # Count Accepted Domains $CustomerDomainsCount = (Get-AcceptedDomain | Where{$_.Name -like "$CustomerName*"}).count $CustomerDomains = Get-AcceptedDomain | Where{$_.Name -like "$CustomerName*"} | Select-Object DomainName | Format-Table -HideTableHeaders | Out-String # Organize info $Billable = $Users + $Room - $DisabledUsers $mailboxTotalSizeInGB = [Math]::Round($mailboxTotalSize/1024/1024, 2) $mailboxTotalArchiveSizeInGB = [Math]::Round($mailboxTotalArchiveSize/1024/1024, 2) $mailboxTotalAndArchiveSizeInGB = $mailboxTotalSizeInGB + $mailboxTotalArchiveSizeInGB # Write the results to file Add-Content $fileName "Klant: $CustomerName" Add-Content $fileName "Gemaakt: $reportTime" Add-Content $fileName "----------------" Add-Content $fileName "Totaal Aantal Postvakken: $mailboxCount" Add-Content $fileName "Gedeelde Postvakken: $Shared" Add-Content $fileName "Kamer Postvakken: $Room" Add-Content $fileName "Uitgeschakelde Gebruikers: $DisabledUsers" Add-Content $fileName "Aantal Domeinen Actief: $CustomerDomainsCount" Add-Content $fileName "Totale Items in Postvakken: $mailboxTotalItemCount" Add-Content $fileName "Totale Items in Archief: $mailboxTotalArchiveItemCount" Add-Content $fileName "Totale Grootte Postvakken: $mailboxTotalSizeInGB GB" Add-Content $fileName "Totale Grootte Archief: $mailboxTotalArchiveSizeInGB GB" Add-Content $fileName "----------------" Add-Content $fileName "Totale Grootte Postvakken en Archieven: $mailboxTotalAndArchiveSizeInGB GB" Add-Content $fileName "Af Te Rekenen Postvakken: $Billable" Add-Content $filename "Totaal Aantal Archieven: $Archive" Add-Content $fileName "----------------" Add-Content $fileName "Domeinen: $CustomerDomains"