溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Powershell獲取Exchange 郵箱用戶配額

發(fā)布時(shí)間:2020-07-11 14:35:20 來(lái)源:網(wǎng)絡(luò) 閱讀:726 作者:duwei025 欄目:系統(tǒng)運(yùn)維
    客戶場(chǎng)景:為很多用戶單獨(dú)配置過(guò)郵箱配額,想重新規(guī)劃,現(xiàn)需要導(dǎo)致所有用戶實(shí)際容量清單
    實(shí)現(xiàn)方式:直接上代碼

#加載Exchange命令
Add-PSSnapin Microsoft.ex*
#主命令
[array]$output = "" | Select Name,ProhibitSendQuota,DBName
$DBs = Get-MailboxDatabase | Select Name,ProhibitSendQuota
foreach ($DB in $DBs) {
[string]$DBQuota = $DB.ProhibitSendQuota
[string]$DBName = $DB.Name
Write-Host "Database $DBName's quota is $DBQuota"
$Mails = Get-Mailbox -Database $DBName | Select Name,ProhibitSendQuota
foreach ($Mail in $Mails) {
if ($Mail.ProhibitSendQuota -eq "Unlimited") {
[string]$MailQuota = $DBQuota
}
else {
[string]$MailQuota = $Mail.ProhibitSendQuota
}

$Temp = "" | Select Name,ProhibitSendQuota,DBName
$Temp.Name = $Mail.Name
$Temp.ProhibitSendQuota = $MailQuota
$Temp.DBName = $DBName
#$Temp

$output += $Temp

}
}
$output | Export-Csv MailQuota.csv -NoTypeInformation -Encoding UTF8
輸出結(jié)果:
Powershell獲取Exchange 郵箱用戶配額
與預(yù)期對(duì)比:
Powershell獲取Exchange 郵箱用戶配額
結(jié)論:如果為用戶配置了不限制容量,則不能正常獲取(客戶實(shí)際環(huán)境中僅為董事長(zhǎng)有配置無(wú)限制,手動(dòng)修正,符合客戶需求),歡迎幫解決此bug

    Update:
    客戶提出了幾點(diǎn)疑問(wèn):
    1. 這個(gè)結(jié)果我無(wú)法看出哪些用戶是有手動(dòng)配置過(guò)的
    2. 我不知道用戶使用了多少,用了多少空間
    3. 需要最后登錄時(shí)間
    4. 我有很多Mail Server,如果我只想獲取一臺(tái)怎么辦?
    5. 我在C盤(pán)打開(kāi)的這個(gè)腳本,但這個(gè)腳本實(shí)際位置在D盤(pán),這個(gè)輸出文件輸出到了C盤(pán)怎么辦?需要輸出到腳本所在的目錄

針對(duì)以上,優(yōu)化了腳本:

  1. 先直接上腳本
    param($Server)
    $outfile = $(Split-Path -Parent $MyInvocation.MyCommand.Definition) + "\" + (Get-Date -UFormat "%Y-%m-%d_%H-%M-%S") + ".csv"
    Write-Host $outfile
    [array]$output = "" | Select Name,DBName,UserQuota,DBQuota,ProhibitSendQuota,TotalItemSize,Use,LastLogonTime
    #Select Name,DBName,UserQuota,DBQuota,ProhibitSendQuota,TotalItemSize,Use
    Add-PSSnapin Microsoft.ex
    if($Server){
    $DBs = Get-MailboxDatabase -Server $Server| Select Name,ProhibitSendQuota
    } else {
    $DBs = Get-MailboxDatabase | Select Name,ProhibitSendQuota
    }
    foreach ($DB in $DBs) {
    [string]$DBQuota = $DB.ProhibitSendQuota
    [string]$DBName = $DB.Name
    Write-Host "Database $DBName's quota is $DBQuota"
    $Mails = Get-Mailbox -Database $DBName -ResultSize unlimited | Select SamaccountName,ProhibitSendQuota
    foreach ($Mail in $Mails) {
    if ($Mail.ProhibitSendQuota -eq "Unlimited") {
    [string]$MailQuota = $DBQuota
    }
    else {
    [string]$MailQuota = $Mail.ProhibitSendQuota
    }
    $TotalItemSize = Get-MailboxStatistics -Identity $Mail.SamaccountName | select TotalItemSize,LastLogonTime
    $TempA = $Mail.ProhibitSendQuota
    $Temp = "" | Select Name,DBName,UserQuota,DBQuota,ProhibitSendQuota,TotalItemSize,Use,LastLogonTime
    $Temp.Name = $Mail.SamaccountName
    $Temp.DBName = $DBName
    if ($TempA -eq "Unlimited") {
    $Temp.UserQuota = $TempA
    } else {
    #$Temp.UserQuota = $TempA.replace(" ","").split("(")[0]
    $Temp.UserQuota = $($TempA -replace " ").Split("(")[0]
    }
    $Temp.DBquota = $($DBQuota -replace " ").Split("(")[0]
    $Temp.ProhibitSendQuota = $($MailQuota -replace " ").Split("(")[0]
    $Temp.TotalItemSize = $($TotalItemSize.TotalItemSize -replace " ").Split("(")[0]
    $Temp.Use = ('{0:n2}' -f $($Temp.TotalItemSize / $Temp.ProhibitSendQuota
    100)) +'%'
    $Temp.LastLogonTime = $TotalItemSize.LastLogonTime
    #$Temp

$output += $Temp

}
}
#$output[1..$output.count]
$output[1..$output.count] | Export-Csv $outfile -NoTypeInformation -Encoding UTF8 -Force

  1. 輸出結(jié)果
    Powershell獲取Exchange 郵箱用戶配額
  2. 腳本執(zhí)掃方式
    a. 直接執(zhí)行則獲取所有用戶
    b. .\xxx.ps1 -Server XX則獲取指定Server上的DB

歡迎補(bǔ)充

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI