千家信息网

powershell 批量获取office365用户邮箱使用容量

发表于:2025-02-07 作者:千家信息网编辑
千家信息网最后更新 2025年02月07日,公司用的office365的Excahnge Online,云端默认有50G容量。2,3年下来,发现销售或者售后的邮箱容量会很快就要到达极限了,为了方便查看那些用户快到使用极限,那肯定要用powers
千家信息网最后更新 2025年02月07日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("xx@domain.com",$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=$idSize=$size}}|Export-Csv -Path C:\Script\size.csv -NoTypeInformation#断开会话Remove-PSSession $Session
0