Share via

PowerShell script disconnecting

Anonymous
2023-02-20T08:55:19+00:00

i am trying to write a script to export all 365 mailbox statistics for monitoring. However,, it is failing when we query all mailboxes. if i set result size to 10 or 200, the scriprt is running perfectly.

if i use -resultsize unlimited, then it run for sometime and showing a msg that PS is conneting for new session , etc....

Could someone please help me?

$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|Export-Csv

Outlook | Windows | Classic Outlook for Windows | For education

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-02-20T10:15:17+00:00

    Dear AustinSundar,

    Good day.

    Thanks for posting in Microsoft Community.

    Regarding your query on PowerShell script disconnecting. Please understand that this query is outside of our support boundaries.

    For you to be assisted properly, please reach out to PowerShell Community by visiting this website Microsoft PowerShell Community; I am sure that our experts from that team can address your query effectively and accurately.

    Thank you for your cooperation and understanding. Please do not hesitate to post your queries in Microsoft Community and we will always do our best to assist you!

    Sincerely,

    Simbarashe | Microsoft Community Moderator

    Was this answer helpful?

    0 comments No comments