RecoverableItems

Iron Contributor

I want to export csv for all users in office 365 with their dumpster size above 50GB.
Plz correct me with the below syntax

Get-Mailbox -ResultSize Unlimited | Foreach{Get-MailboxFolderStatistics $_ -FolderScope RecoverableItems |  Where{$_.FolderAndSubFolderSize -gt 50Gb} | Select Identity,folderandsubfoldersize} | export-csv "c:\report.csv" -notypeinformation

 

for every user i am getting the below error when i execute in shell

Cannot process argument transformation on parameter 'Identity'. Cannot convert value "my user" to type"Microsoft.Exchange.Configuration.Tasks.GeneralMailboxOrMailUserIdParameter". Error: "Cannot convert hashtable to anobject of the following type: Microsoft.Exchange.Configuration.Tasks.GeneralMailboxOrMailUserIdParameter.
Hashtable-to-Object conversion is not supported in restricted language mode or a Data section."
+ CategoryInfo : InvalidData: (:) [Get-MailboxFolderStatistics], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MailboxFolderStatistics
+ PSComputerName : outlook.office365.com

1 Reply

"Identity" is not a good property to use when pipeing cmdlets, try this instead:

 

Get-Mailbox -ResultSize Unlimited | Foreach { Get-MailboxFolderStatistics $_.PrimarySmtpAddress.ToString() -FolderScope RecoverableItems | Select Identity,@{n="Size";e={[double]((($_.FolderAndSubfolderSize.ToString()).split(" "))[2]).trimstart("(")/1GB}}} | ? {$_.Size -ge 5}

 

 

Also note that I've updated the comparison in the where clause, the size returned is a string, not a number, so you cannot compare it to 50GB.