PowerShell: Report To Avoid Hidden Exchange Mailbox Quota Violations

There are two separate quotas for a Microsoft 365 mailbox. One is for the size of the mailbox. The other lesser-known limit is on the recoverable items database.

It is the recoverable items that frequently catch people off-guard. This quota isn’t shown in the admin portal dashboards. Furthermore, the limit is usually only an issue if you have a mailbox on legal hold.

These two things combine to make a frustrating situation. A user’s mailbox can stop due to a quota violation when it isn’t shown as being full on the portal. Here is a link to Microsoft’s documentation on the subject if you would like to know more.

Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline
$Report = @()
$UserMailboxes = (Get-ExoMailbox -ResultSize unlimited -Filter {(RecipientType -eq ‘UserMailbox’)}).UserPrincipalName
Foreach ($Mailbox in $UserMailboxes){
    $MailboxTotalSize = [PSCustomObject]@{
        Name = $Mailbox
        Mailbox = Get-ExoMailboxStatistics -Identity $Mailbox | Select-Object TotalItemSize -ExpandProperty TotalItemSize
        RecoverableItems = Get-ExoMailboxFolderStatistics -Identity $Mailbox -FolderScope RecoverableItems | Select-Object Name,FolderAndSubfolderSize -ExpandProperty FolderAndSubfolderSize |Where-Object {$_.Name -like “*Recoverable*”}
    }
    $Report += $MailboxTotalSize
}
$Report |Export-Csv -Path
“C\Temp\MailboxTrueSizeReport.csv” -NoTypeInformation

I use the report to help prevent quota lockouts at my employer. You will need to run the script from a machine that has the Exchange Online Management Powershell module installed. Executing the script also requires an account with Exchange Online mailbox administrator permissions.

The output is an easy-to-read three-column report. The headers are Name (the user’s UPN), Mailbox, and RecoverableItems. The script takes around one hour per thousand mailboxes on average. This time can vary wildly,  the point is that it’s slow. Don’t let the computer running it go to sleep.

Fix Word Error When Changing Options “The server drafts location you entered for offline editing is not valid…”

I write a lot of documents in Word. You can imagine my frustration this morning when confronted with an error while trying to change a simple option for pen usage. After fiddling about with it for several minutes, I determined that any change of options resulted in the frustrating error.

The error message appears both in a pop-up dialog box and in the Microsoft Office Alerts section of the event viewer. It reads ” The server drafts location you entered for offline editing is not valid or you do not have permission to access that location. Specify a location on your local computer.” What? This is my home computer. I’m not connected to a server.

My first thought was to specify a location and continue on my merry way, but no joy. You cannot edit the field in question because it also causes the error. My next action was to run a repair on Office by going to Settings -> Apps -> Selecting the Office app and then Modify. This didn’t work either.

I found a few other people suggesting various fixes on-line including adding a string value registry key named “Location” with a valid path for the value (example, C:\users\username\documents\) in HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Offline\Options. This workaround did in fact allow the settings to change, but I was not satisfied with this solution. It seems unlikely that Microsoft intends for users to edit the registry on every computer with Word installed on it. Something else was causing this problem.

Eventually I traced the problem down to a OneDrive failure that had occurred on my system a while back. I had previously configured OneDrive to sync files to a D drive. That drive became problematic, so I unlinked my PC from OneDrive synching and removed the disk. Then I re-enabled OneDrive pointing it at the default location on C.

I had not noticed that the Documents library in Windows Explorer remained pointed at the previous location on the D drive, so was the Pictures library. This was the true cause of the error message. Microsoft 365 products save to OneDrive by default. I reset the libraries by right clicking on them, going to the location tab, and clicking the “Restore Default” button. This generates an error, just click ignore.

If you are experiencing this error and the traditional fixes haven’t worked. Try checking the location of your document libraries and ensure they are fully accessible.

Office 365 All-in-One PowerShell Management Console

If you administrate an Office 365 tenant, you’ve undoubtedly discovered that PowerShell is a requirement rather than an option. Using PowerShell with Office 365 isn’t all that different from the on-premises version, but connecting to all the services can be challenging. Often, a task or project requires multiple modules to function.

With a little scripting knowledge we can connect to and manage all of the O365 services at once. I can’t tell you how many times I got half-way through a project only to realize that I didn’t have all the required cmdlets. Logging on to everything each time I use PowerShell saves time and frustration.

To make the code below work, install the PowerShell modules each service requires. Open an elevated PowerShell console (right click, run as administrator). Check the execution policy (Get-ExecutionPolicy), if it is restricted use the following command to change that: Set-ExeuctionPolicy -ExecutionPolicy Unrestricted . Then use the following commands to install all of the tools:

  • Install-Module AzureAD
    • Type A and press Enter (yes to all) when prompted.
  •  Install-Module MSOnline
    • Type A and press Enter (yes to all) when prompted.
  • Install-Module MicrosoftTeams
    • Type A and press Enter (yes to all) when prompted.
  • Install-Module Microsoft.SharePoint.Online.PowerShell
    • Type A and press Enter (yes to all) when prompted.

Copy the code below and save it as a PS1 file named Manage-O365.PS1 in your documents folder. Make a new desktop shortcut with the following path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit “C:\Users\profile\Documents\Manage-O365.ps1” . When you double-click it you’ll be prompted for credentials and the Office 365 organization name. After entering them, a PowerShell console will launch and connect to O365 services. The window stays open until you are done with your tasks.

$UserCredential = Get-Credential
$OrgName = Read-Host "Enter the Name of your Office 365 Organization, Example: Techbloggingfool"
	$ExchangeOnline = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
		Import-PSSession $ExchangeOnline
	Connect-MsolService -Credential $UserCredential
	Connect-AzureAD -Credential $UserCredential
	Connect-MicrosoftTeams -Credential $UserCredential
	Connect-SPOService -Url https://$OrgName-admin.sharepoint.com -Credential $UserCredential

Tip: Save these lines as a snippet in your favorite IDE (Visual Code, ISE, etc.) and you can easily insert them for Office 365 scripting projects.