Powershell office 365ユーザーメールボックス使用容量の一括取得


会社用office 365のExcahnge Onlineで、クラウドのデフォルト容量は50 Gです.
2、3年後、販売やアフターサービスのメールボックスの容量がもうすぐ限界に達することがわかりました.ユーザーが使用限界に近づいていることを簡単に見るために、powershellを使うに違いありません.
添付:PowershellでExchange Onに接続する方法の公式ドキュメントlinehttps://docs.microsoft.com/zh-cn/powershell/exchange/exchange-eop/connect-to-exchange-online-protection-powershell?view=exchange-ps
#  ECH     csv, AD   
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     
$pw=ConvertTo-SecureString -String "Password" -AsPlainText -force
$cre= New-Object System.Management.Automation.PSCredential("[email protected]",$pw)
#  office365
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cre -Authentication Basic -AllowRedirection
#    
Import-PSSession $Session -DisableNameChecking

#  email           
Import-Csv C:\Script\maillist.csv| %{
$id=$_.mail
$size=Get-MailboxStatistics $id | select TotalItemSize

[pscustomobject]@{

email=$id
Size=$size
}

}|Export-Csv -Path C:\Script\size.csv -NoTypeInformation

#    
Remove-PSSession $Session