Forum Discussion
AustinSundar
Feb 21, 2023Copper Contributor
Ps session disconnecting
unable to retrieve all mailbox config. PS session disconnecting or script is not running if we set result size to unlimited. Could someone please help on how to get the below details of all mailboxes? we have around 40000 mailboxes.
$report = @()
$Mbxs = get-mailbox -resultsize unlimited -RecipientTypeDetails userMailbox,sharedmailbox
foreach ($Mbx in $Mbxs)
{
$TotalItemSize = (Get-MailboxStatistics $Mbx.UserPrincipalName).TotalItemSize
$ItemCount = (Get-MailboxStatistics $Mbx.UserPrincipalName).ItemCount
$TotalDeletedItemSize = (Get-MailboxStatistics $Mbx.UserPrincipalName).TotalDeletedItemSize
$ArchiveTotalItemSize = (Get-MailboxStatistics $Mbx.UserPrincipalName -Archive -WarningAction SilentlyContinue).TotalItemSize
$ArchiveItemCount = (Get-MailboxStatistics $Mbx.UserPrincipalName -Archive -WarningAction SilentlyContinue).ItemCount
$ArchiveTotalDeletedItemSize = (Get-MailboxStatistics $Mbx.UserPrincipalName -Archive -WarningAction SilentlyContinue).TotalDeletedItemSize
#$email= Get-Mailbox $mbx | select @{Name='EmailAddresses'; Expression={$_.EmailAddresses -join ","}}
$reportObj = New-Object PSObject
$reportObj | Add-Member NoteProperty -Name "DisplayName" -Value $mbx.DisplayName
$reportObj | Add-Member NoteProperty -Name "RecipientTypeDetails" -Value $mbx.RecipientTypeDetails
$reportObj | Add-Member NoteProperty -Name "PrimarySmtpAddress" -Value $mbx.PrimarySmtpAddress
$reportObj | Add-Member NoteProperty -Name "EmailAddresses" -Value $mbx.EmailAddresses
$reportObj | Add-Member NoteProperty -Name "RetentionPolicy" -Value $mbx.RetentionPolicy
$reportObj | Add-Member NoteProperty -Name "ArchiveName" -Value $mbx.ArchiveName
$reportObj | Add-Member NoteProperty -Name "AutoExpandingArchiveEnabled" -Value $mbx.AutoExpandingArchiveEnabled
$reportObj | Add-Member NoteProperty -Name "TotalItemSize" -Value $TotalItemSize
$reportObj | Add-Member NoteProperty -Name "ItemCount" -Value $ItemCount
$reportObj | Add-Member NoteProperty -Name "TotalDeletedItemSize" -Value $TotalDeletedItemSize
$reportObj | Add-Member NoteProperty -Name "ArchiveTotalItemSize" -Value $ArchiveTotalItemSize
$reportObj | Add-Member NoteProperty -Name "ArchiveItemCount" -Value $ArchiveItemCount
$reportObj | Add-Member NoteProperty -Name "ArchiveTotalDeletedItemSize" -Value $ArchiveTotalDeletedItemSize
$report += $reportObj
}
$report
- Could be the delimiter, I choose ' ; ' but perhaps it's ' , ' for you? And that's pretty slow. It is a lot of mailboxes of course, and how much RAM is PowerShell using in Task Manager during that?
- What does (get-mailbox -resultsize unlimited -RecipientTypeDetails userMailbox,sharedmailbox).count give you?
- AustinSundarCopper Contributorwe have 59488 mailboxes.
- Ok, so it can retrieve them with get-mailbox. I think it's memory related, how much RAM does powershell consume during running the script?
Instead of putting everything in one $report table, you could also export it to one csv with the append parameter. That way it will not consume that much memory