[英]How to get Mailbox size and Archive size in same table - powershell, exchange
im sorry if my english is bad.如果我的英语不好,我很抱歉。 but here is what im trying to do.但这是我想要做的。
atm i have a script that shows Mailbox size. atm 我有一个显示邮箱大小的脚本。 and a script that shows archive size.以及显示存档大小的脚本。 im using these scripts to add information to Hudu later.我稍后会使用这些脚本向 Hudu 添加信息。
is there a way to get this information into one table?有没有办法将这些信息放入一张表中?
below is how i'm getting archive info:以下是我获取存档信息的方式:
#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
the output from that script would look something like this:该脚本的输出如下所示:
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
i would like that table to also show: Mailbox Size, Item count and last logon time.我希望该表还显示:邮箱大小、项目计数和上次登录时间。 like you get by running:就像你通过运行得到的一样:
$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
is there a way to match these to together and get a table with information from both?有没有办法将这些匹配在一起并获取包含两者信息的表格? adding fields into $result
is ofc easy.将字段添加到$result
很容易。 but then the output looks messed up.但随后输出看起来一团糟。 so matching the tables is where im stuck atm.所以匹配表格是我卡在 atm 的地方。
Translating calculated property tables to a single hashtable of properties is pretty straight forward:将计算出的属性表转换为单个属性哈希表非常简单:
Name
value as the key使用Name
值作为键Expression
value as the value使用Expression
值的内容作为值$_
with the name of the source variable (in this case $mbs
)将$_
替换$_
源变量的名称(在本例中$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
})
I updated it a little bit:我更新了一点:
$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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.