I’m trying to create a script that will extract users mailbox sizes and export to CSV, I have a script thanks to a post I found on Spiceworks (credit to @risingflight<\/a> ) and I’ve got it to do what I want, but I’m struggling to get it to sort by mailbox size.<\/p>\n
I tried adding an expression to the end of MailboxUsage = $Stats.TotalItemSize to convert the value to MB but it get’s ignored, likewise I’ve tried using MailboxUsage = $Stats.TotalItemSize.value.ToMB which is also seemingly ignored.<\/p>\n
Below is the code I currently have.<\/p>\n Below is the code I was using, essentially I now want to include other values such as retention policy.<\/p>\n I’m trying to create a script that will extract users mailbox sizes and export to CSV, I have a script thanks to a post I found on Spiceworks (credit to @risingflight<\/a> ) and I’ve got it to do what I want, but I’m struggling to get it to sort by mailbox size.<\/p>\n I tried adding an expression to the end of MailboxUsage = $Stats.TotalItemSize to convert the value to MB but it get’s ignored, likewise I’ve tried using MailboxUsage = $Stats.TotalItemSize.value.ToMB which is also seemingly ignored.<\/p>\n Below is the code I currently have.<\/p>\n Below is the code I was using, essentially I now want to include other values such as retention policy.<\/p>\n Check this site out Export Office 365 Mailbox Size Report Using PowerShell <\/a> and maybe this report too Export Office 365 Archive Mailbox Size Using PowerShell<\/a> they have so many reports you can comb through and a mountain of information.<\/p>","upvoteCount":1,"datePublished":"2022-01-11T12:52:49.000Z","url":"https://community.spiceworks.com/t/exchange-online-mailbox-size-script/821702/2","author":{"@type":"Person","name":"SomewhereinSC","url":"https://community.spiceworks.com/u/SomewhereinSC"}},{"@type":"Answer","text":" You can also use the following script; it exports the data to a csv file named mailboxstas.csv on the Desktop.<\/p>\n $Mailboxes = Get-Mailbox | ? {$_.RecipientTypeDetails -eq “UserMailbox”}<\/p>\n $Result1 = @()<\/p>\n foreach ($Mailboxes in $Mailboxes) {<\/p>\n $a = Get-MailboxStatistics $Mailboxes.Alias | select TotalItemSize,Displayname<\/p>\n $b = Get-MailboxFolderStatistics $Mailboxes.Alias | ? {$.Name -eq “Recoverable Items”} | select @{Expression={};Label=“Name”;}, @{Expression={};Label=“Mailboxsize”;}, @{Expression={$<\/em>.FolderAndSubfolderSize};Label=“RecoverableItemsSize”;}<\/p>\n $b.Mailboxsize= $a.TotalItemSize<\/p>\n $b.Name = $a.Displayname<\/p>\n $Result1 += $b<\/p>\n }<\/p>\n $Result1 | Export-Csv C:\\Users\\Administrator\\Desktop\\mailboxstas.csv -NoTypeInformation<\/p>\n I hope this will help.<\/p>\n
Foreach($users in Get-Mailbox -ResultSize Unlimited){$users | Foreach-Object { \n$user = $_\n$stats = Get-MailboxStatistics $user.Name\nNew-Object -TypeName PSObject -Property @{ \nDisplayName = $User.DisplayName\nRetentionPolicy = $User.RetentionPolicy \nMailboxUsage = $Stats.TotalItemSize\nItemCount = $Stats.ItemCount\n}\n} | Select-Object Displayname,MailboxUsage,ItemCount,RetentionPolicy | \nExport-CSV \"C:\\somepath\\Mailbox_Size.csv\" -NoTypeInformation -Append\n}\n<\/code><\/pre>\n
Get-Mailbox -ResultSize Unlimited |\nGet-MailboxStatistics |\nSelect DisplayName, `\n@{name=\"TotalItemSize (MB)\"; expression={[math]::Round( `\n($_.TotalItemSize.ToString().Split(\"(\")[1].Split(\" \")[0].Replace(\",\",\"\")/1MB),2)}}, `\nItemCount |\nSort \"TotalItemSize (MB)\" -Descending |\nExport-CSV \"C:\\somepath\\Mailbox_Size.csv\"\n<\/code><\/pre>","upvoteCount":4,"answerCount":4,"datePublished":"2022-01-11T11:00:07.000Z","author":{"@type":"Person","name":"andrewstaley","url":"https://community.spiceworks.com/u/andrewstaley"},"suggestedAnswer":[{"@type":"Answer","text":"
Foreach($users in Get-Mailbox -ResultSize Unlimited){$users | Foreach-Object { \n$user = $_\n$stats = Get-MailboxStatistics $user.Name\nNew-Object -TypeName PSObject -Property @{ \nDisplayName = $User.DisplayName\nRetentionPolicy = $User.RetentionPolicy \nMailboxUsage = $Stats.TotalItemSize\nItemCount = $Stats.ItemCount\n}\n} | Select-Object Displayname,MailboxUsage,ItemCount,RetentionPolicy | \nExport-CSV \"C:\\somepath\\Mailbox_Size.csv\" -NoTypeInformation -Append\n}\n<\/code><\/pre>\n
Get-Mailbox -ResultSize Unlimited |\nGet-MailboxStatistics |\nSelect DisplayName, `\n@{name=\"TotalItemSize (MB)\"; expression={[math]::Round( `\n($_.TotalItemSize.ToString().Split(\"(\")[1].Split(\" \")[0].Replace(\",\",\"\")/1MB),2)}}, `\nItemCount |\nSort \"TotalItemSize (MB)\" -Descending |\nExport-CSV \"C:\\somepath\\Mailbox_Size.csv\"\n<\/code><\/pre>","upvoteCount":4,"datePublished":"2022-01-11T11:00:07.000Z","url":"https://community.spiceworks.com/t/exchange-online-mailbox-size-script/821702/1","author":{"@type":"Person","name":"andrewstaley","url":"https://community.spiceworks.com/u/andrewstaley"}},{"@type":"Answer","text":"