Forum Discussion
Does someone have a script already written that outputs 365 mailbox sizes and archive sizes in GB as
Hello,
If anyone has the time to help I would appreciate your help for something that is beyond my skill set. I spent hours on this with no luck
I can output mailbox sizes in GB with this script
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics |
Select-Object -Property @{label=”User”;expression={$_.DisplayName}},
@{label=”Total Size (GB)”;expression={[math]::Round(`
($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)}}
I can output archive mailbox sizes with this script
Get-Mailbox -resultsize unlimited | Select-Object name, @{n="Archive Size";e={(Get-MailboxStatistics -archive $_.identity).TotalItemSize}},@{label="(GB)";expression={[math]::Round(`
($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)}} | ft
I would like a single csv output with both the archive and mailbox sizes next to the person's name and in GB as the measurement.
This script will output both however it won't put them in GB.
connect-msolservice
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking
Set-ExecutionPolicy RemoteSigned
Enable-PSRemoting
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 $ArchiveStats.TotalItemSize
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"
Get-PSSession | Remove-PSSession
I'm asking for someone who has a script or a fix for my script to assist please with the specific change to where in the script great! If your solution is to learn scripting I appreciate the advice but it is unlikely I can come up with the solution.
I tried the IT scripting guys forum and that was the response I got.
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
8 Replies
All you need to do is add the "calculation" to the output, as in replace it with something like this:
Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "Archive Size" -Value
[math]::Round(($ArchiveStats.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)
- Boe DillardIron Contributor
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.