- 1 year ago
PS Get-MailboxfolderStatistics filter on object
In PowerShell, you can use the Get-MailboxFolderStatistics
cmdlet to retrieve folder statistics for a mailbox in Exchange Online or Exchange Server. To filter the output based on specific properties of the mailbox folders, you can use the Where-Object
cmdlet to apply a filter.
Here's an example of how to use the Get-MailboxFolderStatistics
cmdlet with Where-Object
to filter the mailbox folder statistics based on specific properties:
powershell# Connect to Exchange Online or Exchange Server (if not already connected)
# Replace 'your_email@example.com' with the actual email address of the mailbox you want to query
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking
# Get mailbox folder statistics and filter based on a specific property (e.g., folder size greater than 100 MB)
$Mailbox = "user@example.com" # Replace with the actual email address of the mailbox
$FolderStatistics = Get-MailboxFolderStatistics -Identity $Mailbox | Where-Object { $_.TotalItemSize -gt 100MB }
# Display the filtered folder statistics
$FolderStatistics | Select-Object Identity, ItemsInFolder, FolderSize
# End the Exchange session (optional)
Remove-PSSession $Session
In this example, we use the Get-MailboxFolderStatistics
cmdlet to retrieve folder statistics for the mailbox specified in the $Mailbox
variable. We then use the Where-Object
cmdlet to filter the output based on the TotalItemSize
property, which represents the total size of items (emails, attachments, etc.) in the mailbox folder. In this case, we filter for folders with a total size greater than 100 MB.
Please make sure to replace 'your_email@example.com'
with the actual email address of the mailbox you want to query. Additionally, ensure that you have the necessary permissions to access the mailbox information.
After running the script, you should see a list of mailbox folders that meet the specified filter criteria (in this case, folders with a size greater than 100 MB), along with their respective item count and folder size.