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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章