【问题标题】:Exchange - listing mailboxes in an OU with their mailbox sizeExchange - 列出 OU 中的邮箱及其邮箱大小
【发布时间】:2012-04-05 11:15:23
【问题描述】:

我正在尝试为我们已离职 OU 中的所有用户显示所有邮箱及其大小。我似乎非常接近,但我的命令似乎在结果中添加了一些填充。

[PS] C:\Windows\system32>dsquery user "ou=Departed,ou=Staff,dc=COMPANY,dc=local" -limit 4 | dsget user -samid | Get-MailboxStatistics | ft DisplayName, TotalItemSize, ItemCount

还有输出:

Dsquery has reached the specified limit on number of results to display; use a different value for the -limit option to
display more results.The specified mailbox "  samid                 " doesn't exist.
    + CategoryInfo          : NotSpecified: (0:Int32) [Get-MailboxStatistics], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : DD7D7CEA,Microsoft.Exchange.Management.MapiTasks.GetMailboxStatistics

The specified mailbox "  Eka.Tian              " doesn't exist.
    + CategoryInfo          : NotSpecified: (1:Int32) [Get-MailboxStatistics], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : 7F701DFD,Microsoft.Exchange.Management.MapiTasks.GetMailboxStatistics

显然不应该为第一个结果“samid”工作,但“Eka.Tian”存在。为什么要添加所有这些空间?有没有办法可以格式化 dsget 用户的输出,以便与 Get-MailboxStatistics 配合使用?

【问题讨论】:

    标签: powershell exchange-server


    【解决方案1】:

    为什么是 dsquery?

    get-mailbox -OrganizationalUnit "ou=Departed,ou=Staff,dc=COMPANY,dc=local" -resultsize unlimited |
     get-mailboxstatistics | ft DisplayName,TotalItemSize,Itemcount
    

    【讨论】:

    • 哦,我的 :) 我没有看到 -organizationunit 开关。谢谢!
    【解决方案2】:

    我有东西给你,虽然有点晚了。 您只需要使用 OU 和 DC 调整每个 Searchbase、末尾的电子邮件地址和 SMTP 服务器,然后您会收到一封带有 CSV 附件的电子邮件,其中包含每个 OU,其中包含活动和非活动邮箱的计数和一个列表每个邮箱及其参数。 也可以用Windows的Task-Scheduler触发,自动上报。

    Add-PSSnapin Microsoft.Exchange.Management.Powershell.SnapIn;
    $Kunden=Get-ADOrganizationalUnit -Filter * -SearchBase "OU=Kunden,DC=domain,DC=domain"
    $leerzeile ="`n"
    
    #Funktion für 10 GB Kontrolle
    function getUber10 ($name)
    {
    $Uberschreit=0
    $anzahluber10=0
    $anzahl=0
    $UserList = Get-Mailbox -OrganizationalUnit "$name" |Get-MailboxStatistics
    $großen = $UserList |Select TotalItemSize
    for($y=0; $y -lt $großen.Length; $y++){
    if($großen[$y].totalItemSize.value.toMB() -gt 10000){
    $wieoft=$großen[$y].totalItemSize.value.toMB() * 0.0001
    $anzahluber10 = $anzahluber10 +  [Math]::Ceiling($wieoft) - 1
    }
    }
    $anzahluber10
    }
    
    #Liste aller Kunden mit Postfachanzahl
    Get-ADOrganizationalUnit -Filter * -SearchBase "OU=Kunden, DC=domain, DC=domain" |Select-Object Name, @{n="Postfach-Anzahl";e = {(Get-ADUser -Filter {(EmailAddress -like "*@*") -and (Enabled -eq "True")} -SearchBase $_).count}},`
    @{n="Deaktivierte Postfächer";e = {(Get-ADUser -Filter {Enabled -eq "False"} -SearchBase $_).count}}, @{n="10GB-Überschreitungen"; e={ getUber10 -name $_}} `
    | ConvertTo-Csv -Delimiter ";" -NoTypeInformation | % {$_.Replace('"','')} | Out-File C:\ExchangeReport.csv -Append
    
    $leerzeile | Out-File C:\ExchangeReport.csv -Append
    $leerzeile | Out-File C:\ExchangeReport.csv -Append
    
    #Liste der einzelnen Kunden mit Details der Postfächer
    For($i=1; $i -lt $Kunden.Length; $i++){
    $Kunde=$Kunden[$i]
    $Uberschreit=0
    $anzahluber10=0
    $anzahl=0
    $UserList = Get-Mailbox -OrganizationalUnit "$Kunde" |Get-MailboxStatistics
    $großen = $UserList |Select TotalItemSize
    for($x=0; $x -lt $großen.Length; $x++){
    if($großen[$x].totalItemSize.value.toMB() -gt 10000){
    $wieoft=$großen[$x].totalItemSize.value.toMB() * 0.0001
    $anzahluber10 = $anzahluber10 +  [Math]::Ceiling($wieoft) - 1
    }
    }
    
    Get-ADOrganizationalUnit -Identity $Kunden[$i] |Select-Object Name, @{n="Postfach-Anzahl";e = {(Get-ADUser -Filter {(EmailAddress -like "*@*") -and (Enabled -eq "True")} -SearchBase $Kunde).count}}`
    ,@{n="Deaktivierte Postfächer";e = {(Get-ADUser -Filter {Enabled -eq "False"} -SearchBase $_).count}},@{n="10GB-Überschreitungen"; e={$uberschreit= $anzahluber10 ; $uberschreit}}`
    | ConvertTo-Csv -Delimiter ";" -NoTypeInformation | % {$_.Replace('"','')} | Out-File C:\ExchangeReport.csv -Append
    
    Get-Mailbox -OrganizationalUnit "$Kunde" |Select-Object @{n="Kundenname";e={Get-ADOrganizationalUnit -Identity $Kunden[$i] |Select-Object Name}}, Displayname, PrimarySmtpAddress, `
    @{n="Size(MB)";e = {$Fachstat = Get-MailboxStatistics $_.name;$Fachstat.totalItemsize.value.toMB()}}, @{n="Quota";e={$Fachquot=Get-Mailbox $_.name;$Fachquot.ProhibitSendReceiveQuota}},`
     @{n="Aktiv?"; e={Get-ADUser $_.DistinguishedName |select Enabled}}, @{n="Über 10GB?"; e={$uber10 = Get-MailboxStatistics $_.name; if($uber10.totalItemSize.value.toMB() -gt 10000){$uber10.IsValid}else{$uber10.IsQuarantined}}} `
     | ConvertTo-Csv -Delimiter ";" -NoTypeInformation | % {$_.Replace('"','')} | % {$_.Replace('@{Name=','')} | % {$_.Replace('}','')} | % {$_.Replace('@{Enabled=','')} | Out-File C:\ExchangeReport.csv -Append
    
    $leerzeile | Out-File C:\ExchangeReport.csv -Append
    $leerzeile | Out-File C:\ExchangeReport.csv -Append
    }
    
    $Date = Get-DAte -UFormat "%d.%m.%Y"
    Send-MailMessage -to "empfänger@domain.domain" -from "administrator@domain.domain" -Subject "Exchange-Report" -body "Exchange Report of $Date" -SmtpServer "External IP" -Attachments "C:\ExchangeReport.csv"
    Remove-Item C:\ExchangeReport.csv
    

    我用德语写了变量等,我希望没问题;)

    【讨论】:

      猜你喜欢
      • 2010-10-04
      • 1970-01-01
      • 2022-10-25
      • 1970-01-01
      • 2015-01-23
      • 1970-01-01
      • 2014-10-04
      • 2015-06-11
      • 2012-01-11
      相关资源
      最近更新 更多