【问题标题】:How to get Mailbox size and Archive size in same table - powershell, exchange如何在同一个表中获取邮箱大小和存档大小 - powershell,exchange
【发布时间】:2021-12-17 17:11:00
【问题描述】:

如果我的英语不好,我很抱歉。但这是我想要做的。

atm 我有一个显示邮箱大小的脚本。和一个显示档案大小的脚本。我稍后会使用这些脚本向 Hudu 添加信息。

有没有办法将这些信息放到一个表中?

以下是我获取存档信息的方式:

#Getting archive info 
$Result = @() 
$mailboxes = Get-Mailbox -ResultSize Unlimited
$totalmbx = $mailboxes.Count
$i = 1 
$mailboxes | ForEach-Object {
    $i++
    $mbx = $_
    $size = $null
 
    Write-Progress -activity "Processing $mbx" -status "$i out of $totalmbx completed"
 
    if ($mbx.ArchiveStatus -eq "Active") {
        $mbs = Get-MailboxStatistics $mbx.UserPrincipalName
 
        if ($mbs.TotalItemSize -ne $null) {
            $size = [math]::Round(($mbs.TotalItemSize.ToString().Split('(')[1].Split(' ')[0].Replace(',', '') / 1MB), 2)
        }
        else {
            $size = 0 
        }
    }
 
    $Result += New-Object -TypeName PSObject -Property $([ordered]@{ 
            UserName                    = $mbx.DisplayName
            UserPrincipalName           = $mbx.UserPrincipalName
            ArchiveStatus               = $mbx.ArchiveStatus
            ArchiveName                 = $mbx.ArchiveName
            ArchiveState                = $mbx.ArchiveState
            ArchiveMailboxSizeInMB      = $size
            ArchiveWarningQuota         = if ($mbx.ArchiveStatus -eq "Active") { $mbx.ArchiveWarningQuota } Else { $null } 
            ArchiveQuota                = if ($mbx.ArchiveStatus -eq "Active") { $mbx.ArchiveQuota } Else { $null } 
            AutoExpandingArchiveEnabled = $mbx.AutoExpandingArchiveEnabled
        })
}


$Result | Select UserName, UserPrincipalName, ArchiveMailboxSizeInMB, ArchiveWarningQuota, ArchiveQuota, AutoExpandingArchiveEnabled, ArchiveState| Format-Table

该脚本的输出如下所示:

UserName      UserPrincipalNam     ArchiveMailboxSizeInMB     ArchiveWarningQuota               ArchiveQuota                     AutoExpandingArchiveEnabled    ArchiveState
--------      -----------------     ----------------------     -------------------              ------------                     ---------------------------    ------------
User          user@domain.com                        14,12     90 GB (96,636,764,160 bytes)     100 GB (107,374,182,400 bytes)                         False    Local       
User          user@domain.com                                                                                                                          False    None        
User          user@domain.com                                                                                                                          False    None        
User          user@domain.com                         2,42     90 GB (96,636,764,160 bytes)     100 GB (107,374,182,400 bytes)                         False    Local       

我希望该表也显示:邮箱大小、项目计数和上次登录时间。就像你跑步一样:

$mailboxstatspruser = $mailboxes | Get-MailboxStatistics | select-object DisplayName, @{name=”TotalItemSize (GB)”;expression={[math]::Round((($_.TotalItemSize.Value.ToString()).Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1GB),2)}},ItemCount,LastLogonTime

有没有办法将它们匹配在一起并获得一个包含两者信息的表格?在$result 中添加字段很容易。但随后输出看起来一团糟。所以匹配表格是我卡在atm的地方。

【问题讨论】:

    标签: powershell automation microsoft-exchange


    【解决方案1】:

    将计算的属性表转换为单个属性哈希表非常简单:

    1. 使用Name 值作为键
    2. 使用Expression值的内容作为值
    3. $_ 替换为源变量的名称(在本例中为$mbs
        $Result += New-Object -TypeName PSObject -Property $([ordered]@{ 
                UserName                    = $mbx.DisplayName
                UserPrincipalName           = $mbx.UserPrincipalName
                ArchiveStatus               = $mbx.ArchiveStatus
                ArchiveName                 = $mbx.ArchiveName
                ArchiveState                = $mbx.ArchiveState
                ArchiveMailboxSizeInMB      = $size
                ArchiveWarningQuota         = if ($mbx.ArchiveStatus -eq "Active") { $mbx.ArchiveWarningQuota } Else { $null } 
                ArchiveQuota                = if ($mbx.ArchiveStatus -eq "Active") { $mbx.ArchiveQuota } Else { $null } 
                AutoExpandingArchiveEnabled = $mbx.AutoExpandingArchiveEnabled
                'TotalItemSize (GB)'        = [math]::Round((($mbs.TotalItemSize.Value.ToString()).Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)
                ItemCount                   = $mbs.ItemCount
                LastLogonTime               = $mbs.LastLogonTime
            })
    

    【讨论】:

    • bruh ive 尝试并失败了一整天。非常感谢你,哈哈!它就像一个魅力
    【解决方案2】:

    我更新了一点:

    1. 修复了您总是跳过前 2 个邮箱的问题(以 i = 0 开头,循环结束时为 i++)
    2. 添加了可恢复项目文件夹,以便您还可以报告保留大小(非常慢,但很有用)
    3. 增加了邮箱大小
    4. 删除了一些我不需要的东西
    5. 更新到 EXO cmdlet 以提高速度
    $Domain = "*@domain.com" #change to domain you need
    $mailboxes = Get-Mailbox -ResultSize Unlimited -filter "(emailaddresses -like '$Domain') -and (recipienttypedetails -ne 'RoomMailbox')"
    $totalmbx = $mailboxes.Count
    $Result=@()
    $i = 0
    $mailboxes | ForEach-Object {
        
        $mbx = $_
        $size = $null
        $RecoverableItems = $null
        $RecoverableItemsSize = $null
    
        Write-Progress -activity "Processing $mbx" -status "$i out of $totalmbx completed"
        $mbs = Get-EXOMailboxStatistics $mbx.UserPrincipalName
        $Size = [math]::Round(($mbs.TotalItemSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2)
        
        $RecoverableItems = Get-EXOMailboxFolderStatistics $mbx.UserPrincipalName -FolderScope RecoverableItems | Where-Object {$_.name -eq "Recoverable Items"}
        $RecoverableItemsSize = [math]::Round(($RecoverableItems.FolderAndSubfolderSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2)
    
        if ($mbx.ArchiveStatus -eq "Active"){
            $mbsArchive = Get-EXOMailboxStatistics $mbx.UserPrincipalName -archive
            
            if ($mbs.TotalItemSize -ne $null){
                $ArchiveSize = [math]::Round(($mbsArchive.TotalItemSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2)
                $ArchiveRecoverableItems = Get-EXOMailboxFolderStatistics $mbx.UserPrincipalName -Archive -FolderScope RecoverableItems | Where-Object {$_.name -eq "Recoverable Items"}
                $ArchiveRecoverableItemsSize = [math]::Round(($ArchiveRecoverableItems.FolderAndSubfolderSize.ToString().Split('(')[1].Split(' ')[0].Replace(',','')/1MB),2)
    
            }else{
                $ArchiveSize = 0 
                $ArchiveRecoverableItems = 0
                $ArchiveRecoverableItemsSize = 0
    
            }
        }
    
            $Result += New-Object -TypeName PSObject -Property $([ordered]@{ 
                UserName = $mbx.DisplayName
                UserPrincipalName = $mbx.UserPrincipalName
                ArchiveName =$mbx.ArchiveName
                MailboxSizeInMB = $Size
                ArchiveMailboxSizeInMB = $ArchiveSize
                HoldSize = $RecoverableItemsSize
                ArchiveHoldSize = $ArchiveRecoverableItemsSize
            })
        $i++
    }
    $Result | Export-CSV "C:\Temp\Archive-Mailbox-Report.csv" -NoTypeInformation -Encoding UTF8
    

    【讨论】:

      猜你喜欢
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      • 2014-10-04
      • 2020-05-22
      • 2013-03-08
      • 1970-01-01
      相关资源
      最近更新 更多