Exchange Shell – One Liners

Set the Forest Scope
Helps if you have users / objects in another domain in your forest. By default, your scoped to the domain.

Set-ADServerSettings -ViewEntireForest $True

DAG Node into Maintenance
Set-MailboxServer ex1.domain.com -DatabaseCopyActivationDisabledAndMoveNow $True
Set-ServerComponentState –Identity ex1.domain.com –Component HubTransport –State Draining –Requester Maintenance
Suspend-ClusterNode –Name ex1.domain.com
Set-MailboxServer –Identity ex1.domain.com –DatabaseCopyAutoActivationPolicy Blocked

Replication Health of Members in DAG
Assuming Single DAG
Get-DatabaseAvailabilityGroup | Select-Object -ExpandProperty servers |Test-ReplicationHealth

Move Request Failures, Bad Items
Reports

Get-MoveRequest | ?{$_.status -eq “Failed”} | Get-MoveRequestStatistics -IncludeReport | select displayname, targetdatabase, report | fl > mytextfile.txt

Bad Items
(Get-MoveRequest | ?{$_.status -eq “Failed”} | Get-MoveRequestStatistics -IncludeReport).report.baditems

Move Request from a List, Set up
Get-content MyList.txt | Get-Mailbox | New-MoveRequest – SuspendWhenReadyToComplete

Move Requests from a List, Monitoring
Get-Content MyList.txt | Get-Mailbox | Get-MoveRequest | Get-MoveRequestStatistics | group statusdetail

Get-Content MyList.txt | Get-Mailbox | Get-MoveRequest | Get-MoveRequestStatistics | sort percentagecomplete -Descending

Move Requests from a List, Completion
Get-Content MyList.Txt | Get-Mailbox | Get-MoveRequest | ?{$_.status -eq “Autosuspended”} | Resume-MoveRequest

Move Requests, All, Not Completed
Get-MoveRequest | ?{$_.status -notlike “Completed”} | Get-MoveRequestStatistics

Database Connectivity
Get-MailboxServer | Test-MAPIConnectivity | ft server, database, latency, result, error –auto

ExchangeServices
Get-ExchangeServer | foreach {$name = $_.name; Test-ServiceHealth | ft @{Label=”Server”; Expression={$name }}, role,requiredservicesrunning, servicesnotrunning}

Mailbox Statistics from Database – Sort by Size
Get-Mailbox -Database YourDatabase | Get-MailboxStatistics | Select Identity, DisplayName, @{name=”TotalItemSize(MB)”; expression={$_.totalitemsize.value.toMB()}}, ItemCount | Sort “TotalItemSize(MB)” -Descending | Export-CSV YourCSV.csv -NoTypeInformation

Get All Queues
Get-TransportService | get-queue

Disconnected Mailboxes
Get-MailboxDatabase | Get-MailboxStatistics | ?{ $_.DisconnectReason -eq “Disabled” }

Remove Disconnected Mailboxes

Pipe one of the above commands to the below to force removal.
(I recommend waiting the retention period)

| %{Remove-StoreMailbox –Database $_.database –identity $_.mailboxguid –MailboxState Disabled}

Soft Deleted Maiboxes
Get-MailboxStatistics -Database %MyDatabase% | ?{$_.DisconnectReason -eq “SoftDeleted”}

Get-MailboxStatistics -Database dnzmdb01 | ?{$_.DisconnectReason -eq “SoftDeleted”}

Remove Soft Deleted Mailboxes

Pipe one of the above commands to the below to force removal.
(I recommend waiting the retention period)

| %{Remove-StoreMailbox –Database $_.database –identity $_.mailboxguid –MailboxState Softdeleted}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s