im sorry if my english is bad. but here is what im trying to do.
atm i have a script that shows Mailbox size. and a script that shows archive size. im using these scripts to add information to Hudu later.
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. but then the output looks messed up. so matching the tables is where im stuck atm.
CodePudding user response:
Translating calculated property tables to a single hashtable of properties is pretty straight forward:
- Use the
Name
value as the key - Use the contents of the
Expression
value as the value - Replace
$_
with the name of the source variable (in this case$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
})