A running list of quick administrative commands. Nothing complex (I’ll leave that for other blog posts).
Mailbox Management
List mailbox size and status
Get-MailboxStatistics -server {servername}
Export Mailboxes to PST (SP1 or greater)
foreach ($i in (Get-Mailbox)) { New-MailboxExportRequest -Mailbox $i -FilePath “\\server\x$\psts\$($i.Alias).pst” }
Clear Content: Search-Mailbox -id “UserName” -DeleteContent
Remove Content Older than a certain date: Search-Mailbox -identity username -searchquery {(Received:<06/01/2018 AND kind:email)} -DeleteContent -Force
Import PST to Mailbox
New-MailboxImportRequest -Mailbox skieckhafer@prarch.pri -filepath “\\server\m$\psts\import.pst” -SourceRootFolder “Inbox” -TargetRootFolder “Inbox/Subfolder1/Subfolder2” -BadItemLimit 250 -AcceptLargeDataLoss
Export Mailbox Size and Item Count to CSV
Get-MailboxStatistics -Database “Mailbox Database 0600627013” | Select DisplayName,ItemCount,TotalItemSize | Sort-Object TotalItemSize -Descending | Export-CSV x:\temp\mailboxes.csv
Get-MailboxStatistics -server server.local | Select DisplayName, Database, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending | Export-CSV C:\MBSizes.csv
List Foldersize and ItemCount for a given mailbox
Get-Mailbox -identity foo@foobar.com -ResultSize Unlimited | Get-MailboxFolderStatistics -FolderScope All | Sort-Object FolderSize -Descending | Select-Object -First 10 | FT Identity,FolderSize, ItemsInFolder -wrap
List Foldersize and ItemCount for all mailboxes, export to csv
Get-MailboxStatistics -Database “Mailbox Database XXXXXXXXXX” | Select DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending | Export-CSV C:\MBSizes.csv
Get-MailboxStatistics -Database “Mailbox Database XXXXXXXXXX” | Sort -Property TotalItemSize | Format-Table DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToMB)};label=”Size(MB)”}, LastLogonTime, LastLogoffTime, StorageLimitStatus
Manage Move
To clear previous completed move requests (green arrow):
get-moverequest -movestatus completed | remove-moverequest
To view move statistics
Get-MoveRequest -MoveStatus Completed | Get-MoveRequestStatistics
Manage User Thumbnails
Import-RecipientDataProperty -Identity “John Doe” -Picture -FileData ([Byte[]]$(Get-Content -Path “X:\employeephotos\jdoe_thumb.jpg” -Encoding Byte -ReadCount 0))
Set-Mailbox “John Doe” -RemovePicture
Follow with a re-sync of the GAL: Update-GlobalAddressList -Identity “Default Global Address List”
Resource Management
Convert mailbox for use as a resource
Set-Mailbox Room222 -Type { Room | Equipment }
Change maximum duration for a resource calendar (default 1440 mins)
Set-CalendarProcessing -Identity {mailbox} -MaximumDurationInMinutes 5760
Disable Organizer in Subject
Set-CalendarProcessing -Identity {mailbox} -AddOrganizerToSubject $false
Transport Management
Verify recipient is synchronized with EdgeSync
Test-EdgeSynchronization -VerifyRecipient kate@contoso.com
Search Message Tracking Logs with domain wildcard
Get-MessageTrackingLog -Resultsize Unlimited | Where-Object {$_.recipients -like “*@domain.com”}
Search Message Tracking Logs and export to csv
Get-MessageTrackingLog -ResultSize Unlimited -Start “5/1/2016” -End “5/12/2016” | where{$_.sender -like “*@example.com”} | select-object Timestamp,SourceContext,Source,EventId,MessageSubject,Sender,{$_.Recipients} | export-csv C:\ExchangeLogResults.txt
Export Message Tracking Logs to csv
Get-MessageTrackingLog -Sender “foo@foobar.com” -Start “6/18/2018 00:00:00 AM” -End “6/18/2018 13:30:00 PM” | Select Sender,{$_.Recipients},{$_.RecipientStatus},MessageSubject,TimeStamp, EventId, Source, SourceContext,MessageId,InternalMessageId,ClientIP,ClientHostName,ServerIP,ServerHostName,ConnectorId,TotalBytes,RecipientCount,RelatedRecipientAddress,Reference,ReturnPath,MessageInfo | Export-Csv m:\temp\MessageTrackingLog.csv
Anti-Spam Management
List Organizational Junk SCL Threshold
Get-OrganizationConfig | fl SCLJunkThreshold
List individual content filter agent SCL settings on EdgeSync
Get-ContentFilterConfig | fl *SCL*
List individual mailbox anti-spam settings
get-mailbox Alan.Reid | fl *spam*,*SCL
Set individual mailbox anti-spam setting
set-mailbox Alan.Reid -SCLDeleteEnabled $true -SCLDeleteThreshold 9
Find mailboxes with settings that override organizational settings
Get-Mailbox | where {$_.AntispamBypassEnabled -eq $true}
Content Filter
Remove messages with a subject keyword or from address
Search-Mailbox -Identify {alias} -SearchQuery subject:”phrase” -TargetMailbox administrator -TargetFolder “SearchMailbox” -LogLevel Full –DeleteContent
Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery ‘From:foo@foobar.com Subject:”Invoice Approval”‘ -TargetMailbox gthuerk -TargetFolder Inbox -DeleteContent
Remove messages from multiple mailboxes using CSV, with a subject keywords or phrase
Create a CSV file for user mailboxes on which you want to take action. Enter email addresses in column A.
import-csv c:\tmp\Messagesubject.csv | foreach {Search-Mailbox $_.alias -SearchQuery subject:“phrase” -TargetMailbox administrator -TargetFolder “SearchMessage” -LogOnly -LogLevel Full} > c:\tmp\output.txt
Move & Delete Messages:
import-csv c:\tmp\exchange2010.csv | foreach {Search-Mailbox $_.alias -SearchQuery subject:“phrase” -TargetMailbox administrator -TargetFolder “SearchMessage” -DeleteContent -force} > c:\tmp\moveanddel.txt
Delete Messages:
import-csv c:\tmp\exchange2010.csv | foreach {Search-Mailbox $_.alias -SearchQuery subject:“phrase” -DeleteContent -force} > c:\temp\output.txt
Exempt Sender Domains from Content Filter
Use if you have EdgeSync servers with the ContentFilter enabled.
Set-ContentFilterConfig -BypassedSenderDomains @{Add=”domain1.com”,”domain2.com”}
Leave a comment