Exchange 2007获取邮箱大小并发出警告配额

时间:2014-08-11 08:37:29

标签: email powershell exchange-server

我有Exchange 2007,我在TEXT文件中获得了一个用户列表,我需要得到一个这样的表:

显示名称\邮箱大小(MB)\问题警告配额(MB)

user1 \ 25 \ 40

我写了这些文字:

  
    

Add-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin

         
      

$ file = Get-Content c:\ mail.txt

             

foreach($ file in $ file){

             

Get-MailboxStatistics -Identity $ mail | Sort -Property DisplayName |       ft -AutoSize DisplayName,       @ {表达= {$ _ totalitemsize.value.ToMB()};标签=“邮箱       大小(MB)“},| Out-File c:\ mailboxes.txt -Append

    
  
     

}

1)我知道我不能用这个命令得到“IssueWarningQuota”,我需要使用“Get-
   MailBox“,我不知道如何将它添加到输出文件中。

2)当我在输出文件中运行命令时,标题在每个用户中都是重复的,    我怎么能避免这种情况?

谢谢,

利奥尔

1 个答案:

答案 0 :(得分:0)

您可以使用PSObject和Use Export-Csv。

Function ConvertStringSizeToInt64{   [CmdletBinding()]
[OutputType([Int64])]
Param ([Parameter(
        Mandatory=$true, 
        Position=0)]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[string]
$InString
)
Begin
{[Int64]$return = 0}
process 
{   [string]$OutSize = ""
    $InString | Select-String -AllMatches '((?<=\()\d{1,3}|(?<=\,)\d{1,3})' | 
    %{
        $OutSize = ($OutSize+$_.matches.value) -replace " ",""
        $OutSize = [System.Convert]::ToInt64($OutSize)
        $return = $OutSize
    }
}
end
{return $return}
}
# Create Templ Obect
$oT= New-Object psobject
$oT | Add-Member -MemberType NoteProperty -Name DisplayName -Value $null 
$oT | Add-Member -MemberType NoteProperty -Name MAilBoxSize -Value $null
$oT | Add-Member -MemberType NoteProperty -Name IssueWarningQuota -Value $null

Add-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin

$file=Get-Content c:\mail.txt
$R = @()
$file | %{
$T = $oT | select *
$M = Get-Mailbox $_
$T.DisplayName = $M.DisplayName
$T.MAilBoxSize = ConvertStringSizeToInt64 ((Get-MailboxStatistics -Identity $_).totalitemsize)
$T.IssueWarningQuota   =  If ($M.UseDatabaseQuotaDefaults) {ConvertStringSizeToInt64 (Get-MailboxDatabase $M.Database).IssueWarningQuota}
                          Else {ConvertStringSizeToInt64 $M.IssueWarningQuota}
$R +=$T
}
$R | Export-Csv c:\mail.csv
相关问题