Microsoft Exchange Powershell Commands

Export Mailboxes (Ref Microsoft Exchange Knowledge Base)

Simple Request

New-MailboxExportRequest -Mailbox UserName -FilePath "\\SERVERNAME\SHAREDFOLDER\ExportedFileName.pst"

Export an archived mailbox to a network shared folder

New-MailboxExportRequest -Mailbox UserName -FilePath "\\SERVERNAME\SHAREDFOLDER\ExportedFileName.pst" -IsArchive

Export a mailbox with filters

New-MailboxExportRequest -Mailbox UserName -ContentFilter {(body -like "*SearchingKeyWord 1*") -and (body -like "*SearchingKeyWord 2*") -and (Received -lt "01/01/2012")} -FilePath "\\SERVERNAME\SHAREDFOLDER\ExportedFileName.pst"

Export a mailbox with date filters

Example: Exporting all emails from January 1, 2014 00:00:00 to January 31, 2014 23:59:59

New-MailBoxExportRequest -mailbox UserName -ContentFilter {(Received -gt "01/01/2014
00:00:00") -and (Received -lt "02/01/2014 00:00:00")} -FilePath \\SERVERNAME\SHAREDFOLDER\ExportedFileName.pst

Get the list of all mailbox export jobs

Get-MailboxExportRequest

Get the list of all completed/failed/in-progress mailbox export jobs

Get-MailboxExportRequest -Status Completed
Get-MailboxExportRequest -Status Failed
Get-MailboxExportRequest -Status InProgress

Remove all completed export request

Get-MailBoxExportRequest -Status Completed | Remove-MailBoxExportRequest

User’s Calendar

To view the current permissions of a user’s mailbox

Get-MailboxFolderPermission -id mailboxname:\calendar

To remove a shared user from a user’s mailbox

Remove-MailboxFolderPermission -id mailboxname:\calendar -user shareduser@domain.com

To add a shared user to a user’s mailbox

Add-MailboxFolderPermission -id mailboxname:\calendar -user shareduser@domain.com -AccessRights Reviewer

Replace Reviewer with PublishingEditorEditor, Owner.  Please refer this article Add-MailboxFolderPermission for detailed parameters that you can use for this command.

Search and Delete Email Messages (Ref Exchange Knowledge Base)

To search every mailbox for the attachment that has keyword trojan and create a log message in an Administrator mailbox

Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery attachment:trojan* -TargetMailbox administrator -TargetFolder "SearchAndDeleteLog" -LogOnly -LogLevel Full

To search and delete messages that have the subject with the statement “Your bank statement”

Search-Mailbox -Identity "April Stewart" -SearchQuery 'Subject:"Your bank statement"' -DeleteContent

To search every mailbox and delete the messages that have the subject with “Your bank statement” and log it to BackupMailbox mailbox

Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery 'Subject:"Your bank statement"' -TargetMailbox "BackupMailbox" -TargetFolder "AprilStewart-DeletedMessages" -LogLevel Full -DeleteContent

To add a mobile mailbox policy to a mailbox, provided Sales as the name of the policy and tony@contoso.com as the user mailbox

Set-CASMailbox -Identity tony@contoso.com -ActiveSyncMailboxPolicy "Sales"

To see which mailbox policy applied to a mailbox

Get-CASMailbox -Identity tony@contoso.com

To get a list of all users who have Active Sync Enabled

Get-CASMailbox | Where { $_.ActiveSyncEnabled -eq $true } | Select DisplayName, SamAccountName, ActiveSyncEnabled, OWAEnabled | Export-CSV Test.csv

To clean up Recoverable Emails

Search-Mailbox -Identity test -SearchDumpsterOnly -TargetMailbox "Discovery Search Mailbox" -TargetFolder "test-RecoverableItems" -DeleteContent

Get A List of User’s Mailbox with Mailbox Size

get-mailboxdatabase | mailboxstatistics | Sort TotalItemSize | Select DisplayName, TotalI
temSize

Check Database Replication

Get-DatabaseAvailabilityGroup Name_of_Group | %{ $_.Servers | %{ Get-MailboxDatabaseCopyStatus -Server $_ } }

Delete old emails

search-mailbox -id user1 -SearchQuery "Received < 01/01/2015" -TargetMailbox user2 -TargetFolder "Deleted Items" -DeleteContent -Force

or

search-mailbox -id user1 -SearchQuery "Received < 01/01/2015" -DeleteContent -Force

LIST MAILBOXES AND THEIR SIZE ON A SERVER

Get-Mailbox –Server “Server Name” | Get-MailboxStatistics | Sort TotalItemSize -descending | FT Displayname, TotalItemsize, Itemcount,Database –Autosize | more

Get-Mailbox -Database “*04?" | Get-MailboxStatistics | Sort TotalItemSize -descending | Export-Csv C:\MailboxSize-Descending.csv
Get-Mailbox -Database “*04?" | Get-MailboxStatistics | Select DisplayName, TotalItemSize | Sort TotalItemSize -descending
Get-Mailbox | Get-MailboxStatistics | Select DisplayName, TotalItemSize, Database | Sort TotalItemSize -descending
Get-MailboxDatabase -Status | select Name,DatabaseSize,AvailableNewMailboxSpace

 

 

 

Comments are closed