近期由于公司領(lǐng)導(dǎo)要求統(tǒng)計郵箱數(shù)據(jù)庫當(dāng)中用戶郵箱空間使用大小,需要對用戶郵箱進行使用空間統(tǒng)計,對超出80%的使用空間的用戶,進行郵件通知
成都創(chuàng)新互聯(lián)專注于通榆網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供通榆營銷型網(wǎng)站建設(shè),通榆網(wǎng)站制作、通榆網(wǎng)頁設(shè)計、通榆網(wǎng)站官網(wǎng)定制、小程序制作服務(wù),打造通榆網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供通榆網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。#----------------------------------------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郵箱空間使用情況統(tǒng)計";
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%,請及時歸檔郵件或者聯(lián)系IT支持幫助處理。
聯(lián)系方式: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)
以上實現(xiàn)了,領(lǐng)導(dǎo)的要求,可以根據(jù)自己的實際情況調(diào)整相關(guān)代碼,第一次上傳文章,分享知識心得!