0

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

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的地方。

4

2 回答 2

0

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

  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
        })
于 2021-11-03T10:05:30.087 回答
0

我稍微更新了一下:

  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
于 2021-11-05T21:33:42.790 回答