Forum Discussion
Does someone have a script already written that outputs 365 mailbox sizes and archive sizes in GB as
- May 14, 2020
You seem to have inserted a new line there. Try this:
Write-Host "Gathering Stats, Please Wait.." $Mailboxes = Get-Mailbox -ResultSize Unlimited | Select UserPrincipalName, identity, ArchiveStatus $MailboxSizes = @() foreach ($Mailbox in $Mailboxes) { $ObjProperties = New-Object PSObject $MailboxStats = Get-MailboxStatistics $Mailbox.UserPrincipalname | Select LastLogonTime, TotalItemSize, ItemCount Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "UserPrincipalName" -Value $Mailbox.UserPrincipalName Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Last Logged In" -Value $MailboxStats.LastLogonTime Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Mailbox Size" -Value ([math]::Round(($MailboxStats.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)) Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Mailbox Item Count" -Value $MailboxStats.ItemCount if ($Mailbox.ArchiveStatus -eq "Active") { $ArchiveStats = Get-MailboxStatistics $Mailbox.UserPrincipalname -Archive | Select TotalItemSize, ItemCount Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Size" -Value ([math]::Round(($ArchiveStats.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)) Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Item Count" -Value $ArchiveStats.ItemCount } else { Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Size" -Value "No Archive" Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Item Count" -Value "No Archive" } $MailboxSizes += $ObjProperties } $MailboxSizes | Export-csv "C:\inboxsizes.csv" -NoTypeInformation
Thank you so much for your response!
I should be clear - I am OK with about a 1 line script. Anything beyond that is beyond my skill level. I tried to put that in but had no luck. I do appreciate any help but I regret to say I'll need the answer spoon fed as to which script and exactly where to make the changes. I tested with the 3 scripts I posted and couldn't get it to work. I'm not saying your answer isn't helpful - just that I couldn't figure out how to make it work. Thanks again - sorry but powershell eludes me.
Just replace the corresponding line in the "long" script with the one I pasted above - if this generates the output you expect, you can do the same for the other "size" field.
- Boe DillardMay 14, 2020Iron Contributor
Thanks.
I tried this -
Write-Host "Gathering Stats, Please Wait.."
$Mailboxes = Get-Mailbox -ResultSize Unlimited | Select UserPrincipalName, identity, ArchiveStatus
$MailboxSizes = @()
foreach ($Mailbox in $Mailboxes) {
$ObjProperties = New-Object PSObject
$MailboxStats = Get-MailboxStatistics $Mailbox.UserPrincipalname | Select LastLogonTime, TotalItemSize, ItemCount
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "UserPrincipalName" -Value $Mailbox.UserPrincipalName
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Last Logged In" -Value $MailboxStats.LastLogonTime
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Mailbox Size" -Value $MailboxStats.TotalItemSize
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Mailbox Item Count" -Value $MailboxStats.ItemCount
if ($Mailbox.ArchiveStatus -eq "Active") {
$ArchiveStats = Get-MailboxStatistics $Mailbox.UserPrincipalname -Archive | Select TotalItemSize, ItemCount
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Size" -Value[math]::Round(($ArchiveStats.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Item Count" -Value $ArchiveStats.ItemCount
}
else {
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Size" -Value "No Archive"
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Item Count" -Value "No Archive"
}
$MailboxSizes += $ObjProperties
}
$MailboxSizes | Export-csv "C:\inboxsizes.csv"I'm getting
Add-Member : Missing an argument for parameter 'Value'. Specify a parameter of type 'System.Object' and try again.
At line:16 char:118
+ ... t $ObjProperties -MemberType NoteProperty -Name "Archive Size" -Value
+ ~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-Member], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.AddMemberCommand- VasilMichevMay 14, 2020MVP
You seem to have inserted a new line there. Try this:
Write-Host "Gathering Stats, Please Wait.." $Mailboxes = Get-Mailbox -ResultSize Unlimited | Select UserPrincipalName, identity, ArchiveStatus $MailboxSizes = @() foreach ($Mailbox in $Mailboxes) { $ObjProperties = New-Object PSObject $MailboxStats = Get-MailboxStatistics $Mailbox.UserPrincipalname | Select LastLogonTime, TotalItemSize, ItemCount Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "UserPrincipalName" -Value $Mailbox.UserPrincipalName Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Last Logged In" -Value $MailboxStats.LastLogonTime Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Mailbox Size" -Value ([math]::Round(($MailboxStats.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)) Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Mailbox Item Count" -Value $MailboxStats.ItemCount if ($Mailbox.ArchiveStatus -eq "Active") { $ArchiveStats = Get-MailboxStatistics $Mailbox.UserPrincipalname -Archive | Select TotalItemSize, ItemCount Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Size" -Value ([math]::Round(($ArchiveStats.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)) Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Item Count" -Value $ArchiveStats.ItemCount } else { Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Size" -Value "No Archive" Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Item Count" -Value "No Archive" } $MailboxSizes += $ObjProperties } $MailboxSizes | Export-csv "C:\inboxsizes.csv" -NoTypeInformation- Boe DillardMay 14, 2020Iron Contributor
AMAZING work!! Thanks so very much!! I've been kicking that around for over a day with zero progress and you solved it just like that.
This is where I'm at with the code now and if you don't mind - how do I add the user name in addition to their login? If you don't have time - I completely understand you have been wonderful!
Write-Host "Gathering Stats, Please Wait.."
$Mailboxes = Get-Mailbox -ResultSize Unlimited | Select UserPrincipalName, identity, ArchiveStatus
$MailboxSizes = @()
foreach ($Mailbox in $Mailboxes) {
$ObjProperties = New-Object PSObject
$MailboxStats = Get-MailboxStatistics $Mailbox.UserPrincipalname | Select LastLogonTime, TotalItemSize, ItemCount
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "UserPrincipalName" -Value $Mailbox.UserPrincipalName
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Last Logged In" -Value $MailboxStats.LastLogonTime
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Mailbox Size (GB)" -Value ([math]::Round(($MailboxStats.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2))
if ($Mailbox.ArchiveStatus -eq "Active") {$ArchiveStats = Get-MailboxStatistics $Mailbox.UserPrincipalname -Archive | Select TotalItemSize, ItemCount
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Size (GB)" -Value ([math]::Round(($ArchiveStats.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2))
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Item Count" -Value $ArchiveStats.ItemCount}
else {Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Size (GB)" -Value "0"
}$MailboxSizes += $ObjProperties
}
$MailboxSizes | Export-csv "C:\inboxsizes.csv" -NoTypeInformation
Thank you for your wonderful help!