Powershell batch acquires mailbox usage capacity of office365 users
The company uses office365's Excahnge Online, which has a default capacity of 50 gigabytes in the cloud.
2Jing 3 years later, found that the sales or after-sales mailbox capacity will soon reach the limit, in order to facilitate the check of those users who are fast to the limit, it is necessary to use powershell.
Attached: official documentation, how to connect to Exchange Online using powershell
Https://docs.microsoft.com/zh-cn/powershell/exchange/exchange-eop/connect-to-exchange-online-protection-powershell?view=exchange-ps
# get ECH user mailbox to csv Then execute Get-ADUser-SearchBase 'OU=users,DC=domain,DC=com'-Filter {(mail-ne "null")-and (Enabled-eq "true")}-Properties mail | Select-Object mail | export-csv-Path C:\ Script\ maillist.csv-NoTypeInformation#office365 administrator account $pw=ConvertTo-SecureString-String "Password"-AsPlainText-force$cre= New-Object System.Management.Automation.PSCredential ("xx@domain.com") $pw) # Link office365 $Session = New-PSSession-ConfigurationName Microsoft.Exchange-ConnectionUri https://outlook.office365.com/powershell-liveid/-Credential $cre-Authentication Basic-AllowRedirection# create session Import-PSSession $Session-DisableNameChecking# Import email address and output its email capacity Import-Csv C:\ Script\ maillist.csv |% {id=$_.mail$size=Get-MailboxStatistics $id | select TotalItemSize [pscustomobject] @ {email=$idSize=$size} | Export-Csv-Path C:\ Script\ size.csv-NoTypeInformation# disconnect session Remove-PSSession $Session