The author post this script on his GitHub, you can report this issue to bwya77, check whether he could add a timeout parameter to his script.
Mid size tenant powershell times out w/ access denied
I have cobbled together two scripts from here
https://www.thelazyadministrator.com/2018/06/22/create-an-interactive-html-report-for-office-365-with-powershell/ and here https://www.linkedin.com/pulse/documenting-your-office-365-tenant-suzanne-hunt
Now the script runs successfully against a small tenant but against a larger tenant it always ends with the error below. I am launching an elevated powershell session, using a GA account and I confirmed access to the tenant. Any suggestions on how I can get this script to run successfully?
Starting a command on the remote server failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
- CategoryInfo : OperationStopped: (outlook.office365.com:String) [], PSRemotingTransportException
- FullyQualifiedErrorId : JobFailure
- PSComputerName : outlook.office365.com
Starting a command on the remote server failed with the following error message : The I/O operation has been aborted because of either a thread exit or an application request. For more information, see the about_Remote_Troubleshooting Help topic.
- CategoryInfo : OperationStopped: (outlook.office365.com:String) [], PSRemotingTransportException
- FullyQualifiedErrorId : JobFailure
- PSComputerName : outlook.office365.com
3 additional answers
Sort by: Most helpful
-
Vasil Michev 107.7K Reputation points MVP
2021-01-30T08:20:10.027+00:00 That's a common issue with running Exchange Remote PowerShell, you need to add some code to handle throttling and session reconnects. Lots of good suggestions here: https://techcommunity.microsoft.com/t5/exchange-team-blog/running-powershell-cmdlets-for-large-numbers-of-users-in-office/ba-p/604280
-
jpcapone 1,491 Reputation points
2021-01-31T21:20:07.52+00:00 here is the snippet in the script that i think cause the time out
Write-Host "Getting Room Mailboxes..." -ForegroundColor Yellow
$Rooms = Get-Mailbox -ResultSize Unlimited -Filter '(RecipientTypeDetails -eq "RoomMailBox")'
Foreach ($Room in $Rooms)
{
$RoomArray = New-Object 'System.Collections.Generic.List[System.Object]'$RoomName = $Room.DisplayName $RoomPrimEmail = $Room.PrimarySmtpAddress $RoomEmails = ($Room.EmailAddresses | Where-Object { $_ -cnotmatch '^SMTP' }) foreach ($RoomEmail in $RoomEmails) { $RoomEmailSplit = $RoomEmail -split ":" | Select-Object -Last 1 $RoomArray.add($RoomEmailSplit) }
DOES THE BELOW SEEM RIGHT
Start-RobustCloudCommand Write-Host "Getting Room Mailboxes..." -ForegroundColor Yellow
$Rooms = Get-Mailbox -ResultSize Unlimited -Filter '(RecipientTypeDetails -eq "RoomMailBox")'
Foreach ($Room in $Rooms)
{
$RoomArray = New-Object 'System.Collections.Generic.List[System.Object]'$RoomName = $Room.DisplayName $RoomPrimEmail = $Room.PrimarySmtpAddress $RoomEmails = ($Room.EmailAddresses | Where-Object { $_ -cnotmatch '^SMTP' }) foreach ($RoomEmail in $RoomEmails) { $RoomEmailSplit = $RoomEmail -split ":" | Select-Object -Last 1 $RoomArray.add($RoomEmailSplit) }
-
Rich Matheisen 46,811 Reputation points
2021-01-31T22:42:17.09+00:00 This code may not entirely address your problem, but it should begin processing the mailboxes before the Get-Mailbox cmdlet finishes, cutting the elapsed time.
Write-Host "Getting Room Mailboxes..." -ForegroundColor Yellow Get-Mailbox -ResultSize Unlimited -Filter '(RecipientTypeDetails -eq "RoomMailBox")' | Foreach-Object{ $RoomArray = New-Object 'System.Collections.Generic.List[System.Object]' $RoomName = $_.DisplayName $RoomPrimEmail = $_.PrimarySmtpAddress $Room.EmailAddresses | Where-Object { $_ -cnotmatch '^SMTP' } | # might be slightly faster to use "-cnotlike 'SMTP:*' ???" ForEach-Object{ $RoomArray.add(($RoomEmail -split ":")[-1]) } # continue processing this mailbox }
Another thing that may help is to segregate your mailboxes and place those room mailboxes in another OU. Add a search scope to the Get-Mailbox and eliminate the need to look all the 'other' types of mailboxes.