如果我的英語不好,我很抱歉。但這是我想要做的。
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
有沒有辦法將這些匹配在一起并獲取包含兩者資訊的表格?將欄位添加到$resultofc 中很容易。但隨后輸出看起來一團糟。所以匹配表格是我卡在 atm 的地方。
uj5u.com熱心網友回復:
將計算出的屬性表轉換為單個屬性哈希表非常簡單:
- 使用
Name值作為鍵 - 使用
Expression值的內容作為值 - 替換
$_為源變數的名稱(在本例中為$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
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/348789.html
