Exchange 2010 用户邮箱使用空间统计

近期由于公司领导要求统计邮箱数据库当中用户邮箱空间使用大小,需要对用户邮箱进行使用空间统计,对超出80%%u7684使用空间的用户,进行邮件通知

#—————————————-sent to admin and sent to users.
$dblist = Get-MailboxDatabase
$smtpServer = “mail.contoso.com”
$smtpUser = “Administrator”
$smtpPassword = “1234546”
#set the addresses
$MailAddress=”Administrator@contoso.com”
$MailtoAddress=”pengfei@contoso.com”

$userlist = @();

#create the mail message
$mail = New-Object System.Net.Mail.MailMessage
$mail.From = New-Object System.Net.Mail.MailAddress($MailAddress)
$mail.To.Add($MailtoAddress)
#set the content
$mail.Subject = “Q邮箱空间使用情况统计”;

foreach($db in $dblist){
$dbName = $db.Name;

$dbInfo = Get-MailboxDatabase $dbName | select IssueWarningQuota;
$dbWQ = $dbInfo.IssueWarningQuota.Value.ToMB();
$uper= $dbWQ * 0.8;
$object_part = $dbWQ * 0.2;

$alluser=Get-MailboxStatistics -database $dbName |Where-Object {$_.TotalItemSize.Value.ToMB() -ge $uper} | Sort-Object TotalItemSize -Descending | select-object displayname,totalitemsize
$Mailbox = Get-Mailbox -Database $dbName| select-object DisplayName,primarysmtpaddress;

foreach($user in $alluser){
$displayname = $user.DisplayName;
$totalitemsize = $user.TotalItemSize.Value;
$mypriadd= $Mailbox | where-object {$_.DisplayName -eq $displayname;} | select-object primarysmtpaddress;

$mylocal = $mypriadd.PrimarySmtpAddress.Local;
$myadd = $mylocal “@contoso.com”;

$userobject=New-object psobject;
$userobject | Add-Member -membertype noteproperty -Name 用户名 -value $displayname;
$userobject | Add-Member -membertype noteproperty -Name 邮箱已用空间 -Value $totalitemsize;
$userobject | Add-Member -membertype noteproperty -Name 邮件地址 -Value $myadd;
$userlist =$userobject;

if($mylocal -ne $null){
$mail_user = New-Object System.Net.Mail.MailMessage
$mail_user.From = New-Object System.Net.Mail.MailAddress($MailAddress)
#set the content
$mail_user.Subject = “邮箱空间已不足20%”;

#$MailtoAddress_user=$MailtoAddress; #$myadd;
$mail_user.To.Add($myadd)

$EmailbodyHTML_user= “您的邮箱空间不足20%,%u8BF7及时归档邮件或者联系IT支持帮助处理。<br/> 联系方式:Administrator@contoso.com”; #| Out-String # ConvertTo-Html |
$mail_user.Body = $EmailbodyHTML_user;
$mail_user.IsBodyHtml = $true;
#send the message
$smtp_user= New-Object System.Net.Mail.SmtpClient -argumentList $smtpServer;
$smtp_user.Credentials = New-Object System.Net.NetworkCredential -argumentList $smtpUser,$smtpPassword;
$smtp_user.Send($mail_user);
}
}

}

$EmailbodyHTML=$userlist| ConvertTo-Html | Out-String
$mail.Body = $EmailbodyHTML
$mail.IsBodyHtml = $true
#send the message
$smtp = New-Object System.Net.Mail.SmtpClient -argumentList $smtpServer
$smtp.Credentials = New-Object System.Net.NetworkCredential -argumentList $smtpUser,$smtpPassword
$smtp.Send($mail)

以上实现了,领导的要求,可以根据自己的实际情况调整相关代码,第一次上传文章,分享知识心得!

如果,你对上面的内容还有疑问,推荐选择西部数码企业云邮箱!有专人协助您解答邮箱疑问。

西部数码优质企业邮箱服务商,提供安全稳定,简单易用,高性价比的企业邮箱。按需自由定制,不限空间,极速收发,能够满足用户对企业邮箱的不同需求。多种反垃圾邮件算法,99.9%精准度,智能过滤,减少垃圾邮件干扰。支持小程序收发邮件,随时随地移动办公。而且价格实惠,还可以免费试用,7×24小时专业团队服务支持!

高性价比企业邮箱开通链接:https://www.west.cn/services/mail/

赞(0)
声明:本网站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-62778877-8306;邮箱:fanjiao@west.cn。本站原创内容未经允许不得转载,或转载时需注明出处:西部数码知识库 » Exchange 2010 用户邮箱使用空间统计

登录

找回密码

注册