powershell 批量獲取office365用戶郵箱使用容量

公司用的office365的Excahnge Online,雲端默認有50G容量。

2,3年下來,發現銷售或者售後的郵箱容量會很快就要到達極限了,爲了方便查看那些用戶快到使用極限,那肯定要用powershell.

附:官方文檔,如何用powershell連接到Exchange Online
https://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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章