Collection of Shell commands for Microsoft Exchange 2010
Exchange 2010 Database Status PowerShell CMDlets
Status for all database copies on the Mailbox server by status
Get-MailboxDatabaseCopyStatus -Server <servername> | Sort-Object -Property Status| ft mailboxserver,DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy,ErrorMessage -AutoSize
Get Database Copy Status
Get-MailboxDatabaseCopyStatus -Identity <servername> | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Get High Copy Queue Length in Organization
get-mailboxserver | Get-MailboxDatabaseCopyStatus | sort-object -property copyqueuelength -des | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Get Error Information for Seeding
Get-MailboxDatabaseCopyStatus -Identity <servername> | fl name,Status,Errormessage
Get Quick Health Status of Copies in DAG
Get-DatabaseAvailabilityGroup Ex10DAG1 | %{ $_.Servers | %{ Get-MailboxDatabaseCopyStatus -Server $_ } }
Get all copies of Failed Databases in DAG
Get-mailboxserver | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed*”} | Sort-Object -Property DatabaseName| ft DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy -AutoSize
Get Mounted Databases in DAG and status
Get-mailboxserver | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “mounted” } | Sort-Object -Property DatabaseName| ft MailboxServer,status, ActiveCopy,DatabaseName, Copyqueuelength,Replayqueuelength, ContentIndexState -AutoSize
Status information for ALL Database copies in DAG sorted by Status
Get-mailboxserver | Get-MailboxDatabaseCopyStatus | Sort-Object -Property Status | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Status information for ALL Database copies in DAG sorted by Copyqueuelength
Get-mailboxserver | Get-MailboxDatabaseCopyStatus | Sort-Object -Property copyqueuelength -descending | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Get ALL non-healthy COPIES in DAG
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where ({$_.Status -ne “healthy” -and $_.Status -ne “mounted” })| sort name |ft name, Status, LatestFullBackupTime, ActiveCopy -autosize
Get ALL database copies in DAG sorted by Content Index State
Get-mailboxserver | Get-MailboxDatabaseCopyStatus | Sort-Object -Property ContentIndexState | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Get ALL database copies on a Server sorted by Database
Get-MailboxDatabaseCopyStatus -Server <servername> |sort name | ft DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy -AutoSize
Get Active Database Copies in DAG
Get-mailboxserver | Get-MailboxDatabaseCopyStatus |? {$_.ActiveCopy -eq $true} | Sort-Object -Property DatabaseName| ft DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy -AutoSize
Status for all database copies on the Mailbox server by name
Get-MailboxDatabaseCopyStatus -Server <servername> | SORT NAME| ft mailboxserver,DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy,ErrorMessage -AutoSize
Status for all database copies on the Mailbox server (simple)
Get-MailboxDatabaseCopyStatus -Server <servername> | Sort-Object -Property DatabaseName | ft DatabaseName, MailboxServer, Status -autosize
Get all copies of Failed Databases on Server
Get-MailboxDatabase -server <servername> | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed”} | ft Databasename,status -autosize
Get Active Copies on Server
Get-MailboxDatabaseCopyStatus -Server <servername> |? {$_.ActiveCopy -eq $true} | ft DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy -AutoSize
Get ALL non-healthy Passive COPIES on a Server
Get-MailboxDatabaseCopyStatus -Server <servername> | where ({$_.Status -ne “healthy” -and $_.Status -ne “mounted” })| sort name |ft name, Status, LatestFullBackupTime, ActiveCopy -autosize
Get status for all copies of a particular database
Get-MailboxDatabaseCopyStatus -Identity ‘database name′ | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Get Status for all database copies on the Mailbox server (extensive details)
Get-MailboxDatabaseCopyStatus -Server <servername> | fl DatabaseName, Status, ActiveDatabaseCopy, ActivationSuspended, ContentIndexState, ContentIndexErrorMessage, ReplayQueueLength, LastCopiedLogTime, ErrorMessage
Get Database and Log Paths
Get-MailboxDatabase <database name> | fl *path*
Find Database Log file location
Get-MailboxDatabase <database name> | fl logfolderpath
See if Circular Enabled is enabled for a database
Get-MailboxDatabase -Identity <database name> | fl Name, CircularLoggingEnabled
Check the Mount Status of a Mailbox Database
Get-MailboxDatabase -Status | Select Name, Server, Mounted
Dismount a Mailbox Database
Dismount-Database “database name″
Get Local Database Status
Get-MailboxDatabaseCopyStatus -Local | fl DatabaseName, ContentIndexState, Status,CopyQueueLength,ContentIndexState,LatestFullBackupTime,ActiveCopy,ErrorEventID,errormessage
Status information for all copies of the database and details
Get-MailboxDatabaseCopyStatus -Identity ‘database name′ | fl name, server, activationpreference,Status,CopyQueueLength,ContentIndexState,LatestFullBackupTime,ActiveCopy,ErrorEventID,errormessage
Status information for all copies of the databases in DAG and details
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where {$_.Status -ne $healthy}| fl name, server, Status, CopyQueueLength, ContentIndexState, LatestFullBackupTime, ActiveCopy,ErrorEventID,errormessage
Get ALL MOUNTED Mailbox Databases and Find the Active Servers and details
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | ? {$_.ActiveCopy -eq $true} | sort name | ft mailboxserver,DatabaseName, Status,ContentIndexState -autosize
Get All Database Copy
Get-MailboxDatabaseCopy
Move Database Path
Move-DatabasePath -Identity “database name” -EdbFilePath “path to move”
Ex: Move-DatabasePath -Identity “database name” -EdbFilePath E:\db\Ex10mbx19.edb
Block all databases hosted on a server from Activating
Set-MailboxServer –identity <server name> –DatabaseCopyAutoActivationPolicy Blocked
Test-ReplicationHealth cmdlet to test the health of replication for the Mailbox server
Test-ReplicationHealth -Identity <server name>
Exchange Event Log CMDlets
To view only the Exchange-related services that are currently running
Get-Service *exch* | Where-Object {$_.Status -eq ‘Running’}
The following example retrieves the services from every Exchange server in the organization:
Get-ExchangeServer | ForEach-Object {Get-Service *exch* -ComputerName $_.Name |Where-Object {$_.Status -eq ‘Running’}}
Get Events after specified Date
Get-EventLog -LogName application -after 1/8/2013 | where {$_.Entrytype -eq “Error”} | ft -wrap -autosize
Get Events after specified Date and Source
Get-EventLog -LogName application -after 1/8/2013 -source MSExchangeIS | Ft -wrap -autosize
Get Events after specified Date with Source only Warning and Error
Get-EventLog -LogName application -after 1/8/2013 -source MSExchangeIS | where {($_.Entrytype -eq “Warning” -or $_.Entrytype -eq “Error”)} -wrap -autosize
Get Specificied number of Events with Source only Warning and Error
Get-EventLog -LogName application -Newest 50 -source MSExchangeIS | where {($_.Entrytype -eq “Warning” -or $_.Entrytype -eq “Error”)} -wrap -autosize
Get Application Events after specified Date and Entrytype with a Specified word in the Message Field
Get-EventLog -LogName application -after 1/8/2013 | where {$_.Entrytype -eq “Error”}| Where-Object { $_.Message -match “mailbox” } | ft -wrap -autosize
Get Application Events after specified Date, Source and Entrytype with a Specified word in the Message Field
Get-EventLog -LogName application -after 1/8/2013 -source MSExchangeIS | where {($_.Entrytype -eq “Warning” -or $_.Entrytype -eq “Error”)}| Where-Object { $_.Message -match “mailbox” } | ft -wrap -autosize
Get Event by INDEX (unique qualifier)
Get-EventLog -LogName application -index 163303 | ft -wrap -autosize
Message Tracking CMDlets
Search by Message ID
Get-ExchangeServer | get-messagetrackinglog -MessageID “<messageID>” -Start “5/16/2012 12:01:00 AM” -End “5/16/2012 11:59:00 PM” | fl Timestamp,ClientIp,ClientHostname,ServerIp,ServerHostname,Source,EventId,MessageId, @{Name=”Recipients”;Expression={$_.recipients}},@{Name=”Recipientstatus”;Expression={$_.recipientstatus}},TotalBytes,MessageSubject,Sender,ReturnPath,MessageLantency
Search by Sender
Get-ExchangeServer | get-messagetrackinglog -sender user@domain.com -Start “11/15/2012 12:00:00 AM” -End “11/16/2012 11:59:00 PM” | fl Timestamp,ClientIp,ClientHostname,ServerIp,ServerHostname, Source,EventId,MessageId, @{Name=”Recipients”;Expression={$_.recipients}},@{Name=”Recipientstatus”;Expression={$_.recipientstatus}},TotalBytes,MessageSubject,Sender
Search by Recipient
Get-ExchangeServer | get-messagetrackinglog -recipient user@domain.com -sender user@domain.com -Start “11/15/2012 12:00:00 AM” -End “11/16/2012 11:59:00 PM” | fl Timestamp,ClientIp,ClientHostname,ServerIp,ServerHostname, Source,EventId,MessageId, @{Name=”Recipients”;Expression={$_.recipients}},@{Name=”Recipientstatus”;Expression={$_.recipientstatus}},TotalBytes,MessageSubject,Sender
Get Message Size of messages in MB
fl Sender,@{label=”size”;Expression={$_.Totalbytes/1mb}}
Search by Sender, Recipient and Subject
Get-ExchangeServer | get-messagetrackinglog -sender user@domain.com -recipient user@domain.com -Start “12/13/2012 12:01:00 AM” -End “12/13/2012 11:59:00 PM” -messagesubject ‘test’ | fl Timestamp,ClientIp,ClientHostname,ServerIp,ServerHostname, Source,EventId,MessageId, @{Name=”Recipients”;Expression={$_.recipients}},@{Name=”Recipientstatus”;Expression={$_.recipientstatus}},TotalBytes,MessageSubject,Sender,ReturnPath,MessageLantency
Search by Sender and Subject
Get-ExchangeServer | get-messagetrackinglog -sender user@domain.com -messagesubject ‘subject’ -Start “5/16/2012 12:00:00 AM” -End “5/16/2012 11:59:00 PM” | fl Timestamp,ClientIp,ClientHostname,ServerIp,ServerHostname, Source,EventId,MessageId, @{Name=”Recipients”;Expression={$_.recipients}},@{Name=”Recipientstatus”;Expression={$_.recipientstatus}},TotalBytes,MessageSubject,Sender,ReturnPath,MessageLantency
Search by Recipient, Subject where the Event ID is failed
Get-ExchangeServer | get-messagetrackinglog -recipient user@domain.com -messagesubject “subject” -Start “10/10/2012 3:01:00 PM” -End “10/10/2012 9:59:00 PM” | where {$_.EventID -eq “Failed”}| fl Timestamp,MessageID, @{Name=”Recipients”;Expression={$_.recipients}},MessageSubject,EventID,Sender,ReturnPath
Search for messages blocked by transport rule
Get-ExchangeServer | get-messagetrackinglog -recipient user@domain.com -Start “10/10/2012 3:01:00 PM” -End “10/10/2012 9:59:00 PM” | where {$_.SourceContext -eq “Transport Rule Agent”}| fl Timestamp,Sender,MessageSubject,Source,EventId,MessageId, @{Name=”Recipients”;Expression={$_.recipients}},TotalBytes,SourceContext
Search by Subject
Get-ExchangeServer | get-messagetrackinglog -messagesubject ‘subject’ -Start “5/16/2012 12:00:00 AM” -End “5/16/2012 11:59:00 PM”| fl Timestamp,ClientIp,ClientHostname,ServerIp,ServerHostname, Source,EventId,MessageId, @{Name=”Recipients”;Expression={$_.recipients}},@{Name=”Recipientstatus”;Expression={$_.recipientstatus}},TotalBytes,MessageSubject,Sender,ReturnPath,MessageLantency
Search by Server and Recipient
get-messagetrackinglog -Server “server” -recipient user@domain.com -Start “9/22/2011 11:15:00 AM” -End “9/22/2011 12:15:00 PM” | fl Timestamp,ClientIp,ClientHostname,ServerIp,ServerHostname, Source,EventId,MessageId, @{Name=”Recipients”;Expression={$_.recipients}},@{Name=”Recipientstatus”;Expression={$_.recipientstatus}},TotalBytes,MessageSubject,Sender,ReturnPath,MessageLantency
Search all Hub Servers for Messages sent to Recipient
Get-ExchangeServer | Get-MessageTrackingLog -sender user@domain.com -Recipient user@domain.com -EventID “RECEIVE” -Start “9/30/2011 12:01:00 AM” -End “9/30/2011 11:59:00 PM” | fl Timestamp,MessageId, @{Name=”Recipients”;Expression={$_.recipients}},TotalBytes,MessageSubject,Sender,ReturnPath
Search all Hub Servers for Messages via MessageID
Get-ExchangeServer | get-messagetrackinglog -MessageID “<messageID>” -Start “12/13/2012 12:01:00 AM” -End “12/13/2012 11:59:00 PM” | fl Timestamp,ClientIp,ClientHostname,ServerIp,ServerHostname, source,EventId,MessageId, @{Name=”Recipients”;Expression={$_.recipients}},@{Name=”Recipientstatus”;Expression={$_.recipientstatus}},TotalBytes,MessageSubject,Sender,ReturnPath,MessageLantency ,sourcecontext
Search for Rejected Messages by searching agent logs
Get-AgentLog |?{ ($_.p1fromaddress -match “domain.com” -or $_.p2fromaddresses -match “domain.com”) -and $_.action -eq “RejectMessage”
Search for all mail sent between a specific time from a sender from the ‘contoso.com’ domain
get-messagetrackinglog -start “7/20/2011 6:00pm” -End “7/21/2011 4:30pm” -resultsize UNLIMITED -eventid “SEND” | where {[string]$_.sender -like “*@contoso.com”}
Search for all mail sent between a specific time from a sender from the ‘contoso.com’ domain to recipients on the ‘contoso.com’ domain
get-messagetrackinglog -start “7/20/2011 6:00pm” -End “7/21/2011 4:30pm” -resultsize UNLIMITED -eventid “SEND” | where { [string]$_.sender -like “*contoso.com” -and [string]$_.recipients -like “*@contoso.com” } | fl Sender,TimeStamp, @{Name=”Recipients”;Expression={$_.recipients}},MessageSubject
Mail Queue Management CMDlets
Get Message Queue information
Get-transportserver | Get-Queue –SortOrder: -MessageCount
Get Queue Details
Get-Queue –Server <server name> | Sort-Object -Property Messagecount | FT Identity, DeliveryType, NextHopDomain, Status, MessageCount, LastRetryTime, LastError -autosize
Move Messages to Another Working Queue
In the event a Hub Transport server is completely out, you may have the requirement to move all messages in a queue to another Hub Transport server in your organization to ensure the messages are delivered. How can you do this?
First you need to export all messages in the current queue. You can do this with the following powershell commands:
$array = @(Get-Message -Queue “QueueName” -ResultSize unlimited)
$array | ForEach-Object {$i++;Export-Message $_.Identity | AssembleMessage -Path (“c:\MailsExport\”+ $i +”.eml”)}
To import the messages into the new Hub Transport server, simply place the .eml files into the Transport Pickup folder. The new server should immediately start processing the messages.
Get Specific Queue
Get-Queue Server\Queue
Get all Queues and sort by Message Count
Get-TransportServer | Get-Queue -sortorder: -messagecount
Get all Queues with Retry Status sorted by messagecount
Get-TransportServer | Get-Queue -sortorder: -messagecount | where {$_.Status -eq “Retry”} | fl
Get Queues greater than 25
Get-TransportServer | Get-Queue -Filter {MessageCount -gt 25}
Retry Queues where the next hop domain is ‘domain.com’
Retry-Queue -Filter {NextHopDomain -eq “domain.com” -and Status -eq “Retry”}
Resume Queues on Server1 where the next hop domain is ‘domain.com’
Resume-Queue -Server Server1 -Filter {NextHopDomain -eq “domain.com”}
This example suspends processing on all queues on server Server1.contoso.com that have more than 100 messages in the queue.
Suspend-Queue -Server Server1.contoso.com -Filter {MessageCount -gt 100}
This example suspends processing on all queues holding messages for delivery to the domain contoso.com and that currently have a status of Retry.
Suspend-Queue -Filter {NextHopDomain -eq “contoso.com” -and Status -eq “Retry”}
Checking Mailbox Integrity CMDlets
Detect
New-MailboxRepairRequest -Mailbox user@domain.com -CorruptionType ProvisionedFolder,SearchFolder -DetectOnly
Repair Corruption
New-MailboxRepairRequest -Mailbox user@domain.com -CorruptionType ProvisionedFolder,SearchFolder,AggregateCounts,Folderview
Managing Groups CMDlets
Get Distribution Group
Get-DistributionGroup -identity ‘user@domain.com’ | fl
Get Distribution Group Members and export to text file
Get-DistributionGroupMember -Identity ‘group@domain.com’ | ft name, primarysmtpaddress > c:\path\file.txt
Get Distribution Group information
Get-DistributionGroup -Identity ‘group@domain.com’ | fl DisplayName, Alias, PrimarySmtpAddress, EmailAddresses, RecipientType, HiddenFromAddressListsEnabled, LastExchangeChangedTime, LegacyExchangeDN, WhenChanged, WhenCreated, WhenChangedUTC, WhenCreatedUTC, AcceptMessagesOnlyFrom, AcceptMessagesOnlyFromDLMembers, AcceptMessagesOnlyFromSendersOrMembers, CustomAttribute*
Add Group member when group is secured
Add-DistributionGroupMember -identity “Group1″ -Member “User1″ -BypassSecurityGroupManagerCheck
Get-Distribution Group Members
Get-DistributionGroupMember -identity “Group1″
Use when troubleshooting Who has permissions to send to group
Get-DistributionGroup -Identity ‘group@domain.com’ | fl DisplayName,PrimarySmtpAddress, RecipientType, HiddenFromAddressListsEnabled, LastExchangeChangedTime, AcceptMessagesOnlyFrom, AcceptMessagesOnlyFromDLMembers, AcceptMessagesOnlyFromSendersOrMembers, CustomAttribute*
Find out if External Senders are allowed to send to Distribution Group
Get-DistributionGroup -Identity ‘group@domain.com’ | ft name,primarysmtpaddress,require* -AutoSize
Find which groups require Sender Authenication
Get-DistributionGroup | where {$_.RequireSenderAuthenticationEnabled -ne “true”} | sort-object -property Alias | Ft Alias,RequireSender
Resource Rooms and Calendars CMDlets
Disable Double Booking of Meeting Rooms
Set-CalendarProcessing -Identity ‘room’ -AllowConflicts:$false
Disable Double Booking on all Meeting Rooms
Get-Mailbox | where {$_.ResourceType -eq “Room” } | Set-CalendarProcessing -AllowConflicts:$false
Get Status of Meeting Rooms Calendars
Get-CalendarProcessing -Identity room | fl
Get Calendar Permissions for user
Get-MailboxFolderPermission roomname@domain.org:\calendar
Grant read rights to the calender in the “MeetingRoom” calendar
Add-MailboxFolderPermission MeetingRoom@domain.local:\calendar -User Default -AccessRights reviewer
Grant members of the AD group Admins read and write access to the calendar.
(The AD group must be mail enabled and cannot be hidden from the address book when executing the command).
Add-MailboxFolderPermission MeetingRoom@domain.local:\calendar -User Admins -AccessRights editor
Remove access rights for the default user on mailbox
Remove-MailboxFolderPermission MeetingRoom@domain.local:\calendar -User Default -AccessRights editor
Set Reviewer permissions to the default account
Set-MailboxFolderPermission -Identity MeetingRoom@domain.local:\Calendar -User Default -AccessRights Reviewer
Mailbox Move CMDlets
Get a count of all mailboxes in database (per DB)
Get-mailboxdatabase -identity <database name> | Get-Mailbox -resultsize unlimited | Group-Object -Property:Database | FT name,count -AutoSize
Use this command to view how many move requests are in the queue to be moved:
(Get-MoveRequest -MoveStatus Queued).count
Find the number of Move requests that haven’t completed:
(Get-moverequest -resultsize unlimited | Get-moverequeststatistics| where {$_.Status -notlike “completed*”}).count
Get Good Mailbox Move information for Moves in Progress
Get-moverequest -MoveStatus InProgress | Get-moverequeststatistics| ft DisplayName,PercentComplete,TotalMailboxSize,Bytes* -AutoSize
Get Mailbox Move information by BATCH NUMBER
Get-moverequest -resultsize unlimited |get-moverequeststatistics |where ({$_.Batchname -like “acct” -and $_.Status -ne “completed”})| sort-object -Property Status -descending | ft Displayname, status, percentcomplete -AutoSize
Get Mailbox Move information by BATCH NUMBER and good information
Get-moverequest | Get-moverequeststatistics| ft DisplayName,batchname,PercentComplete,TotalMailboxSize,Bytestransferredperminute -AutoSize
Get Move Status by Database
Get-moverequest -resultsize unlimited | Get-moverequeststatistics| where {$_.SourceDatabase -like “<source database name>″} | Sort-Object -Property PercentComplete -Descending | ft DisplayName, batchname, SourceDatabase,PercentComplete,Status -AutoSize
Get Mailbox Moves that are NOT completed
Get-moverequest -resultsize unlimited | Get-moverequeststatistics| where {$_.Status -notlike “completed*”} | Sort-Object -Property PercentComplete -Descending | ft DisplayName, batchname, SourceDatabase,PercentComplete,Status -AutoSize
Get Mailbox Moves that are Completing
Get-moverequest -resultsize unlimited | Get-moverequeststatistics| where {$_.Status -eq “completing”} | Sort-Object -Property PercentComplete -Descending | ft DisplayName, batchname, SourceDatabase,PercentComplete,Status -AutoSize
Use these commands to get a snapshot of the move throughput for completed moves.
$stats = Get-MoveRequest -MoveStatus Completed | Get-MoveRequestStatistics
$stats | sort totalmailboxsize | ft Alias,{$_.totalmailboxsize.ToMB()},totalinprogressduration -auto
Get Mailbox Moves that are NOT completed by Database
Get-moverequest -resultsize unlimited | Get-moverequeststatistics| where {$_.SourceDatabase -like “<database name>″ -and $_.Status -ne “completed”} | Sort-Object -Property PercentComplete -Descending | ft DisplayName, batchname, SourceDatabase,PercentComplete,Status -AutoSize
Get Mailbox Moves by Source DB that are pending completion (Auto Completion)
Get-moverequest -resultsize unlimited | Get-moverequeststatistics| where {$_.SourceDatabase -like “<database name>″ -and $_.Status -eq “autosuspended”} | Sort-Object -Property PercentComplete -Descending | ft DisplayName,PercentComplete,TotalMailboxSize,Bytestransferredperminute ,status -AutoSize
Get Mailbox Moves by Batch that are pending completion (Auto Completion)
Get-moverequest -resultsize unlimited | Get-moverequeststatistics| where {$_.Batchname -like “batch1″ -and $_.Status -eq “autosuspended”} | Sort-Object -Property PercentComplete -Descending | ft DisplayName, batchname, SourceDatabase,PercentComplete,Bytestransferredperminute, Status -AutoSize
Get Mailbox Moves that are Suspended
Get-moverequest -resultsize unlimited | Get-moverequeststatistics| where {$_.Status -eq “suspended”} | Sort-Object -Property PercentComplete -Descending | ft DisplayName, batchname, SourceDatabase,PercentComplete,Status -AutoSize
Get Suspended Moves and resume move requests
Get-MoveRequest -resultsize unlimited -MoveStatus Suspended | Resume-MoveRequest
Get Mailbox Moves that are NOT completed and resume them
Get-moverequest -resultsize unlimited | Get-moverequeststatistics| where {$_.Status -ne “completed”} | Resume-MoveRequest
Get Failed Moves and resume move requests
Get-MoveRequest -resultsize unlimited -MoveStatus Failed | Resume-MoveRequest
Get Autosuspended Moves and resume move requests
Get-MoveRequest -resultsize unlimited -MoveStatus Autosuspended | Resume-MoveRequest
Get Completed Moves and Remove move requests
Get-MoveRequest -resultsize unlimited -MoveStatus Completed | Remove-MoveRequest
Get Mailbox Moves that are NOT completed and remove requests
Get-moverequest -resultsize unlimited | Get-moverequeststatistics| where {$_.Status -notlike “completed*”} | Remove-MoveRequest
Remove completed moves by Batch
Get-moverequest -resultsize unlimited |get-moverequeststatistics |where ({$_.Batchname -like “batch1 to batch2″ -and $_.Status -eq “completed”})| Remove-MoveRequest
Get-Mailbox Move Statistics with Great Details
Get-MoveRequest -resultsize unlimited| Get-MoveRequestStatistics |Sort-Object CompletionTimeStamp| ft DisplayName, @{Expression={$_.BadItemsEncountered};Label=”Errors”}, @{Expression={$_.PercentComplete};Label=”Percent”}, @{Expression={$_.TotalMailboxSize.ToString().Split(“(“)[0]};Label=”Size”}, @{Expression={$_.totalinprogressduration};label=”Time”},@{Expression={(($_.BytesTransferred/$_.TotalInProgressDuration.TotalMinutes)*60).ToString().Split(“(“)[0]};Label=”Pace/hr”}, @{Expression={$_.MRSServerName.ToString().Split(“.”)[0]};Label=”CAS”}, @{Expression={$_.SourceDatabase.ToString().Split(“\”)[0]};Label=”SourceServer”},SourceDatabase,Status,CompletionTimestamp -auto
Get-Mailbox Move Statistics with Great Details and export
Get-MoveRequest -resultsize unlimited| Get-MoveRequestStatistics |Sort-Object status| ft DisplayName, @{Expression={$_.BadItemsEncountered};Label=”Errors”}, @{Expression={$_.PercentComplete};Label=”Percent”}, @{Expression={$_.TotalMailboxSize.ToString().Split(“(“)[0]};Label=”Size”}, @{Expression={$_.totalinprogressduration};label=”Time”},@{Expression={(($_.BytesTransferred/$_.TotalInProgressDuration.TotalMinutes)*60).ToString().Split(“(“)[0]};Label=”Pace/hr”}, @{Expression={$_.MRSServerName.ToString().Split(“.”)[0]};Label=”CAS”}, @{Expression={$_.SourceDatabase.ToString().Split(“\”)[0]};Label=”SourceServer”},SourceDatabase,Status,CompletionTimestamp -auto > c:\dame.txt
Cancel Move Request for one user
Get-moverequest -Identity ‘user’ | Remove-MoveRequest
Get Move request ERROR status for Failed jobs
Get-moverequest -resultsize unlimited |get-moverequeststatistics |where ({$_.Batchname -like “batch” -and $_.Status -eq “failed”})| sort-object -Property Status -descending | fl DisplayName,batchname,sourcedatabase,targetdatabase,overallduration,mrsservername,totalmailboxsize,totalmailboxitemcount,percentcomplete,failurecode,failuretype,message,failuretimestamp
Get Move request ERROR status for Failed jobs
Get-moverequest -resultsize unlimited |get-moverequeststatistics |where {$_.Status -eq “failed”}| sort-object -Property Status -descending | fl DisplayName,batchname,sourcedatabase,targetdatabase,overallduration,mrsservername,totalmailboxsize,totalmailboxitemcount,percentcomplete,failurecode,failuretype,message,failuretimestamp
Get move details for ongoing moves
Get-moverequest -resultsize unlimited |get-moverequeststatistics |where ({$_.Batchname -like “batch” -and $_.Status -ne “completed”})| sort-object -Property Status -descending | ft DisplayName,batchname,status,targetdatabase,overallduration,mrsservername,percentcomplete -autosize
Find number of moves that haven’t completed
(Get-moverequest -resultsize unlimited |get-moverequeststatistics |where {$_.Batchname -like “batch” -and $_.Status -ne “completed”}).count| ft -autosize
Create a local move request
New-MoveRequest -Identity ‘user@domain.com’ -TargetDatabase <database name>
Create a move request that suspends before completion
New-MoveRequest -Identity ‘user@domain.com’ -TargetDatabase <database name> -SuspendWhenReadyToComplete
Remove \ Clear completed move requests
Get-MoveRequest -resultsize unlimited -MoveStatus queued | Remove-MoveRequest
Resume Failed Requests
Get-MoveRequest -resultsize unlimited -MoveStatus Failed | Resume-MoveRequest
Create a move request processed by a specific server
New-MoveRequest -Identity ‘user@domain.com’ -TargetDatabase <database name> -MRSServer exchsrv1.domain.com
Move a user’s primary mailbox and allow a large bad item limit
New-MoveRequest -Identity ‘user@domain.com’ -TargetDatabase <database name> -BadItemLimit 100 -AcceptLargeDataLoss
Managing Mailbox Permissions CMDlets
Grant Send on Behalf of Permissions
Set-Mailbox ‘user@domain.com’ -GrantSendOnBehalfTo ‘user@domain.com’
Add Editor permissions
Add-MailboxFolderPermission -Identity ‘user@domain.com’ -User ‘user@domain.com’ -AccessRights Editor
Add Reviewer permissions (what if)
Set-MailboxFolderPermission -Identity ‘user@domain.com’ -User ‘user@domain.com’ -AccessRights Reviewer -whatif
Getting Mailbox Folder Permissions
Get-MailboxFolderPermission -Identity ‘user@domain.com’ | fl
Get-MailboxFolderPermission -Identity user@domain.com:\inbox
Impersonation Rights
new-ManagementRoleAssignment Name:RoleName -Role:ApplicationImpersonation -User:’domain\alias’
Get User Mailbox Permissions other than Inherited Permissions
Get-MailboxPermission -identity ‘user@domain.com’ | Where-Object {($_.AccessRights -like “*FullAccess*”) -and ($_.User -notlike “NT AUTHORITY\SELF”) -and ($_.IsInherited -eq $false)}
Get ALL User Mailbox Permissions
Get-MailboxPermission ‘user@domain.com’ | ft -AutoSize
Get User Mailbox Permissions (defined)
Get-MailboxPermission ‘user@domain.com’ | ft User,AccessRights -AutoSize
Use this command to find who is being rejected from sending to the target mailbox
get-mailbox -Identity ‘target mailbox’ | fl name, *reject*
Find Mailbox Folder Stats on folder
Get-MailboxFolderStatistics ‘user@domain.com’ | Where { $_.FolderPath.Contains(“FolderName”) -eq $true }
Find Mailbox Folder Stats on folder and add permissions
ForEach($f in (Get-MailboxFolderStatistics John | Where { $_.FolderPath.Contains(“/Clients”) -eq $True } ) ) {$fname = “John:” + $f.FolderPath.Replace(“/”,”\”); Add-MailboxFolderPermission $fname -User Jane -AccessRights Reviewer }
Remember
Set-MailboxFolderPermission cmdlet only updates existing folder-level permissions for all folders within a user’s mailbox
Add-MailboxFolderPermission cmdlet adds new permissions to mailbox
Grant Full Access and SendAs Permissions
Add-MailboxPermission -Identity ‘user@domain.com’ -User ‘user alias’ -AccessRights FullAccess
Add-ADPermission ‘user alias’ -User ‘user alias’ -Extendedrights “Send As”
View Send As permission (use display name)
Get-ADPermission ‘User Display name)’ | select user,extendedrights
Remove Full Access mailbox permission
Remove-MailboxPermission -Identity ‘user@domain.com’ -User domain\alias -AccessRights FullAccess -InheritanceType all
Get AD Permission ‘not inherited’, like local domain users
Get-Mailbox -identity ‘User Alias’ | Get-ADPermission | where {($_.IsInherited -eq $false) -and ($_.User -like “Test_USERS*”)} | select User, extendedrights
Get Mailbox Permission ‘not inherited’, like local domain users
Get-MailboxPermission -Identity user@domain.com | where {($_.IsInherited -eq $false) -and ($_.User -like “Test_USERS*”)} | select User,Accessrights | FT
Get AD Permission ‘not inherited’
Get-Mailbox -identity ‘User Name’ | Get-ADPermission | where {($_.IsInherited -eq $false)} | select User, extendedrights
Get AD Permission ‘not inherited’, like local domain users
Get-Mailbox -identity ‘User Name’ | Get-ADPermission | where {($_.IsInherited -eq $false) -and ($_.User -like “Pilot*”)} | select User, extendedrights
Get Mailbox Permission ‘not inherited’, like local domain users
Get-MailboxPermission -Identity user@domain.com | where {($_.IsInherited -eq $false) -and ($_.User -like “Pilot*”)} | select User,Accessrights | FT
Grant Read Only permissions
Add-MailboxPermission -Identity “User Name” -User “domain\user” -AccessRights ReadPermission
Remove Read Only permissions
remove-MailboxPermission -Identity “User Name” -User “domain\user” -AccessRights ReadPermission
Set Read Only Permisions to existing
Set-MailboxFolderPermission -Identity user@domain.com -User user@domain.com -AccessRights Reviewer
Set-MailboxFolderPermission -Identity user@domain.com -User ‘domain\user’ -AccessRights Reviewer
Grant Users full access permissions to mailboxes
Add-MailboxPermission -Identity user@domain.com -User ‘User’ -AccessRights FullAccess
Grant Full Access to a Room Mailbox
Add-MailboxPermission -Identity ‘Conference-Room’ -User ‘user@domain.com’ -AccessRights FullAccess
When you assign full access rights to a mailbox, you may notice that the change does not take effect immediately, and the user that has been granted permissions to a mailbox still cannot access that resource. This is because the Information Store service uses a cached mailbox configuration that by default is only refreshed every two hours. You can force the cache to refresh by restarting the Information Store service on the mailbox server that is hosting the active database where the mailbox resides.
Get ‘Send on Behalf of’ permissions
Get-Mailbox -identity ‘user@domain.com’ | fl name, grant*
Set Send on Behalf permissions
Set-Mailbox UserMailbox -GrantSendOnBehalfTo UserWhoSends
Remove Users full access permissions to mailboxes
Remove-MailboxPermission -Identity user1 -User user2 -AccessRights FullAccess -Confirm:$false
Grant Group full access permissions to mailbox
Add-MailboxPermission -Identity user -User “Help Desk” -AccessRights FullAccess
Mailbox Import \ Exports CMDlets
Export a Mailbox to PST
New-MailboxExportRequest -Mailbox user@domain.org -FilePath “\\path\user.pst”
Get Mailbox Export Requests
Get-MailboxExportRequest | Get-MailboxExportRequestStatistics
Remove Mailbox Export Requests
Get-MailboxExportRequest | Remove-MailboxExportRequest
Export Mailbox to PST
New-MailboxExportRequest -Mailbox user@domain.org -FilePath “\\path\user.pst”
Import Mailbox to PST
New-MailboxImportRequest -Mailbox user@domain.org -FilePath “\\path\user.pst”
Get Mailbox Import Requests
Get-MailboxImportRequest | Get-MailboxImportRequestStatistics
DAG Management CMDLETS
Get DAG Status
Get-DatabaseAvailabilityGroup <dag name> -Status | fl
StartDagServerMaintenance.ps1 script to put the DAG member in maintenance mode
.\StartDagServerMaintenance.ps1 -serverName <server name>
StopDagServerMaintenance.ps1 script to take the DAG member out of maintenance mode
.\StopDagServerMaintenance.ps1 -serverName <server name>
Find DatabaseCopyAutoActivationPolicy for all Servers
Get-MailboxServer | Sort-Object -Property DatabaseCopyAutoActivationPolicy | ft name,DatabaseCopyAutoActivationPolicy -AutoSize
Get Maintenance Status
Get-DatabaseAvailabilityGroup <dag name> -Status | fl Servers, ServersInMaintenance
Get ALL Databases and Active Preference information NEAT
Get-MailboxDatabase | Sort Name | ft Name,ServerName,MountedOnServer, ActivationPreference -AutoSize
Get Databases sorted by Active Server
Get-MailboxDatabase | Sort-Object -Property MountedonServer | ft Name,ServerName,MountedOnServer, ActivationPreference -AutoSize
Get Number of Databases in DAG
(Get-MailboxDatabase).count
Get All databases and Activation Preference information
Get-MailboxDatabase | ft name, server, activationpreference -AutoSize
Get Specific databases and Activation Preference information
Get-MailboxDatabase -Identity ‘<database name>′ | fl name, server, activationpreference
Get Primary Active Manager (PAM)
Get-DatabaseAvailabilityGroup -Identity <dag name> -Status | fl name,primaryactivemanager
Move PAM to another server
cluster.exe <dag name> group “cluster group” /moveto:<server name>
To block DB activation (switch site as needed)
Get-ExchangeServer | where { $_.Site -like ‘DOMAIN.ORG/Configuration/Sites/Site’ } | Get-MailboxServer | Set-MailboxServer –DatabaseCopyAutoActivationPolicy Blocked
Enable DAC Mode
Set-DatabaseAvailabilityGroup –identity “<dag name>” –DatacenterActivationMode DagOnly
Run RedistributeActiveDatabases.ps1 script to re-balance the active database copies across the DAG
.\RedistributeActiveDatabases.ps1 -DagName <dag name> -BalanceDbsByActivationPreference -ShowFinalDatabaseDistribution -Confirm:$false > DagConfig.txt
Remove Server from Dag
Remove-DatabaseAvailabilityGroupServer -Identity <dag name> -MailboxServer <server name>
Add Server to DAG
ADD-DatabaseAvailabilityGroupServer -Identity <dag name> -MailboxServer <server name>
Unblock all databases hosted on a server
Set-MailboxServer –identity <server name> –DatabaseCopyAutoActivationPolicy Unrestricted
Block all databases hosted on Server
Set-MailboxServer –identity <server name> –DatabaseCopyAutoActivationPolicy Blocked
Set Mailbox Database Copy Activation Copy
Set-MailboxDatabaseCopy -Identity EX10MBX02\EX10SRV02 -ActivationPreference 1
To block a database copy from getting activated automatically
Suspend-MailboxDatabaseCopy –identity EX10mbx01\EX10SRV03 –ActivationOnly
To reverse the unblock process
Resume-MailboxDatabaseCopy –identity EX10mbx04\EX10SRV13
Basic Exchange Database CMDLETS
Get ALL Databases and Active Preference information NEAT
Get-MailboxDatabase | Sort Name | Select Name, ActivationPreference
Get All databases and Activation Preference information
Get-MailboxDatabase | ft name, server, activationpreference -AutoSize
Get Specific databases and Activation Preference information
Get-MailboxDatabase -Identity ‘<database name>′ | fl name, server, activationpreference
Set or Move Active Database
Move-ActiveMailboxDatabase -Identity ‘<database name>′ -ActivateOnServer ‘<server name>′ -MountDialOverride ‘None’
Get Local Database Status
Get-MailboxDatabaseCopyStatus -Local | fl DatabaseName, ContentIndexState, ActiveCopy
Move Database Path
Move-DatabasePath -Identity <database name> -EdbFilePath “file path”
Check the Mount Status of a Mailbox Database
Get-MailboxDatabase -status | fl Name,Mounted
Database Mounted Status
Get-MailboxDatabase -Status | Select Name, Server, Mounted
Dismount a Mailbox Database
Dismount-Database “<database name>″
Export All Users in the database
Get-Mailbox -Database <database name> -ResultSize Unlimited > c:\dame\export1.txt
Get Exchange Database Size (exch 2010)
Get-MailboxDatabase -Status | select ServerName,Name,DatabaseSize
Get Exchange Database Size (exch 2007)
Get-MailboxDatabase | foreach-object {add-member -inputobject $_ -membertype noteproperty -name mailboxdbsizeinGB -value ([math]::Round(([int64](get-wmiobject cim_datafile -computername $_.server -filter (‘name=”’ + $_.edbfilepath.pathname.replace(“\”,”\\”) + ””)).filesize / 1GB),2)) -passthru} | Sort-Object mailboxdbsizeinGB -Descending | format-table identity,mailboxdbsizeinGB
Get All Users in specific Mailbox Database like 2003 View
Get-MailboxStatistics -Database “Mailbox Database” | Sort -Property TotalItemsize | Format-Table DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToMB()};label=”Size(MB)”}, LastLogonTime, LastLogoffTime
Exchange 2010 Database Statistics Powersell CMDlets
Get Number of Mailboxes Per Database (Global)
get-mailbox -resultsize unlimited | group-object -property Database –noelement
Get a count of all mailboxes in database (per DB)
Get-mailboxdatabase -identity <mailbox database> | Get-Mailbox -resultsize unlimited | Group-Object -Property:Database | FT name,count -AutoSize
Get a count of all mailboxes in Exchange
Get-Mailbox -resultsize unlimited | Group-Object -Property:Database | FT name,count -AutoSize
Get Name of Database with the lease amount of users
Get-MailboxDatabase | Select-Object Name,@{Name=”Count”;Expression={Get-MDBMailboxCount -DN $_.DistinguishedName}} | Sort-Object count
Get Database Quotas
Get-MailboxDatabase | ft name,ProhibitSendReceiveQuota,ProhibitSendQuota,RecoverableItemsQuota,RecoverableItemsWarningquota, IssueWarningQuota -auto
Set Database Quotas
Set-MailboxDatabase -identity <mailbox database> -ProhibitSendReceiveQuota 2.3GB -ProhibitSendQuota 2GB -IssueWarningQuota 1.899GB
Get WhiteSpace for database
Get-MailboxDatabase -identity <mailbox database> -Status | Select Servername, Name, AvailableNewMailboxSpace
Get All Mailbox Sizes over 1GB in Database and sort them by size
Get-MailboxStatistics -Database ‘<mailbox database>′ | where {$_.Totalitemsize -gt 1GB} | Sort-Object -Property TotalItemSize -Descending | Format-Table DisplayName,TotalItemSize
Get Database Mounted Status
Get-MailboxDatabase -Status | Select Name, Server, Mounted
Get ALL Quotas for the Database
Get-MailboxDatabase -Identity “<mailbox database>″ | fl *quota*
Export All Users in the database
Get-Mailbox -Database EX10mbx01 -ResultSize Unlimited > c:\dame\export.txt
Get all Exchange Database Sizes in DAG
Get-MailboxDatabase -Status | Sort-Object -Property DatabaseSize -descending | ft ServerName,Name,DatabaseSize -autosize
Get Single Database Size
Get-MailboxDatabase -identity <mailbox database> -Status | ft ServerName,Name,DatabaseSize -autosize
Get All Users in specific Mailbox Database like 2003 View
Get-MailboxStatistics -Database “Mailbox Database” | Sort -Property TotalItemsize | Format-Table DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToMB()};label=”Size(MB)”}, LastLogonTime, LastLogoffTime
Status information for all copies of the database and details
Get-MailboxDatabaseCopyStatus -Identity ‘<mailbox database>′ | fl name, server, activationpreference,Status,CopyQueueLength,ContentIndexState,LatestFullBackupTime, ActiveCopy,ErrorEventID,errormessage
Get ALL MOUNTED Mailbox Databases and Find the Active Servers
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | ? {$_.ActiveCopy -eq $true} | sort name | ft mailboxserver,DatabaseName, Status,ContentIndexState -autosize
Status for all database copies on the Mailbox server EX1001
Get-MailboxDatabaseCopyStatus -Server <server name>| fl DatabaseName, ContentIndexState, ActiveCopy, CopyQueueLength
Get All Database Copy
Get-MailboxDatabaseCopy
Get Number of Mailboxes Per Database (Global)
get-mailbox -resultsize unlimited | group-object -property Database –noelement
Get a count of all mailboxes in database (per DB)
Get-mailboxdatabase -identity <mailbox database> | Get-Mailbox -resultsize unlimited | Group-Object -Property:Database | FT name,count -AutoSize
Get a count of all mailboxes in Exchange
Get-Mailbox -resultsize unlimited | Group-Object -Property:Database | FT name,count -AutoSize
Get Name of Database with the lease amount of users
Get-MailboxDatabase | Select-Object Name,@{Name=”Count”;Expression={Get-MDBMailboxCount -DN $_.DistinguishedName}} | Sort-Object count
Get Database Quotas
Get-MailboxDatabase | ft name,ProhibitSendReceiveQuota,ProhibitSendQuota, RecoverableItemsQuota,RecoverableItemsWarningquota,IssueWarningQuota -auto
Set Database Quotas
Set-MailboxDatabase -identity <mailbox database> -ProhibitSendReceiveQuota 2.3GB -ProhibitSendQuota 2GB -IssueWarningQuota 1.899GB
Get WhiteSpace for database
Get-MailboxDatabase -identity <mailbox database> -Status | Select Servername, Name, AvailableNewMailboxSpace
Get All Mailbox Sizes over 1GB in Database and sort them by size
Get-MailboxStatistics -Database ‘<mailbox database>′ | where {$_.Totalitemsize -gt 1GB} | Sort-Object -Property TotalItemSize -Descending | Format-Table DisplayName,TotalItemSize
Get Database Mounted Status
Get-MailboxDatabase -Status | Select Name, Server, Mounted
Get ALL Quotas for the Database
Get-MailboxDatabase -Identity “<mailbox database>″ | fl *quota*
Export All Users in the database
Get-Mailbox -Database <mailbox database> -ResultSize Unlimited > c:\dame\export.txt
Get all Exchange Database Sizes in DAG
Get-MailboxDatabase -Status | Sort-Object -Property DatabaseSize -descending | ft ServerName,Name,DatabaseSize -autosize
Get Single Database Size
Get-MailboxDatabase -identity <mailbox database> -Status | ft ServerName,Name,DatabaseSize -autosize
Get All Users in specific Mailbox Database like 2003 View
Get-MailboxStatistics -Database “Mailbox Database” | Sort -Property TotalItemsize | Format-Table DisplayName, LastLoggedOnUserAccount, ItemCount, @{expression={$_.totalitemsize.value.ToMB()};label=”Size(MB)”}, LastLogonTime, LastLogoffTime
Status information for all copies of the database and details
Get-MailboxDatabaseCopyStatus -Identity ‘<mailbox database>′ | fl name, server, activationpreference,Status,CopyQueueLength,ContentIndexState,LatestFullBackupTime,ActiveCopy,ErrorEventID,errormessage
Get ALL MOUNTED Mailbox Databases and Find the Active Servers
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | ? {$_.ActiveCopy -eq $true} | sort name | ft mailboxserver,DatabaseName, Status,ContentIndexState -autosize
Status for all database copies on the Mailbox server EX1001
Get-MailboxDatabaseCopyStatus -Server <server name> | fl DatabaseName, ContentIndexState, ActiveCopy, CopyQueueLength
Get All Database Copy
Get-MailboxDatabaseCopy
Get Deleted Item retention Stats
Get-mailboxdatabase | sort-object name | ft name,deleteditemretention -AutoSize
Database Maintenance and Management CMDLETS
Defrag Mailbox Database
eseutil /d EX10mbx01.edb /t E:\DB\EX10mbx05\defrag\EX10mbx01_temp.edb
Disable Exchange Search for a mailbox database
Set-MailboxDatabase “<mailbox database>″ -IndexEnabled $FALSE
Enable Exchange Search for a mailbox database
Set-MailboxDatabase “<mailbox database>″ -IndexEnabled $TRUE
Get Status of Database Indexing
Get-MailboxDatabase | Sort-Object -Property IndexEnabled | ft name, IndexEnabled -autosize
Set Circular Logging for Database
Set-MailboxDatabase -identity <mailbox database> -CircularloggingEnabled:$true
Get Databases with Provisioning
Get-MailboxDatabase | sort name | ft name, *provisioning* -auto
Get Databases in Circular Logging
Get-MailboxDatabase | Sort-Object -Property CircularLoggingEnabled | ft name, CircularloggingEnabled -autosize
Get Status of Backups
Get-MailboxDatabase -status | sort-object -property lastfullbackup | ft name,lastfullbackup -auto
Exchange 2010 Database Status PowerShell CMDlets
Status for all database copies on the Mailbox server Ex10CHM10 by status
Get-MailboxDatabaseCopyStatus -Server <server name> | Sort-Object -Property Status| ft mailboxserver,DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy,ErrorMessage -AutoSize
Get Database Copy Status
Get-MailboxDatabaseCopyStatus -Identity ‘<mailbox database>′ | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Get High Copy Queue Length in Organization
get-mailboxserver | Get-MailboxDatabaseCopyStatus | sort-object -property copyqueuelength -des | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Get Error Information for Seeding
Get-MailboxDatabaseCopyStatus -Identity ‘<mailbox database>′ | fl name,Status,Errormessage
Get Quick Health Status of Copies in DAG
Get-DatabaseAvailabilityGroup <dag name> | %{ $_.Servers | %{ Get-MailboxDatabaseCopyStatus -Server $_ } }
Get all copies of Failed Databases in DAG
Get-mailboxserver | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed*”} | Sort-Object -Property DatabaseName| ft DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy -AutoSize
Get Mounted Databases in DAG and status
Get-mailboxserver | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “mounted” } | Sort-Object -Property DatabaseName| ft MailboxServer,status, ActiveCopy,DatabaseName, Copyqueuelength,Replayqueuelength, ContentIndexState -AutoSize
Status information for ALL Database copies in DAG sorted by Status
Get-mailboxserver | Get-MailboxDatabaseCopyStatus | Sort-Object -Property Status | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Status information for ALL Database copies in DAG sorted by Copyqueuelength
Get-mailboxserver | Get-MailboxDatabaseCopyStatus | Sort-Object -Property copyqueuelength -descending | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Get ALL non-healthy COPIES in DAG
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where ({$_.Status -ne “healthy” -and $_.Status -ne “mounted” })| sort name |ft name, Status, LatestFullBackupTime, ActiveCopy -autosize
Get ALL database copies in DAG sorted by Content Index State
Get-mailboxserver | Get-MailboxDatabaseCopyStatus | Sort-Object -Property ContentIndexState | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Get ALL database copies on a Server sorted by Database
Get-MailboxDatabaseCopyStatus -Server <server name> |sort name | ft DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy -AutoSize
Get Active Database Copies in DAG
Get-mailboxserver | Get-MailboxDatabaseCopyStatus |? {$_.ActiveCopy -eq $true} | Sort-Object -Property DatabaseName| ft DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy -AutoSize
Status for all database copies on the Mailbox server by name
Get-MailboxDatabaseCopyStatus -Server <server name> | SORT NAME| ft mailboxserver,DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy,ErrorMessage -AutoSize
Status for all database copies on the Mailbox server EXCHSRV01 (simple)
Get-MailboxDatabaseCopyStatus -Server EXCHSRV01 | Sort-Object -Property DatabaseName | ft DatabaseName, MailboxServer, Status -autosize
Get all copies of Failed Databases on Server
Get-MailboxDatabase -server EXCHSRV01 | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed”} | ft Databasename,status -autosize
Get Active Copies on Server
Get-MailboxDatabaseCopyStatus -Server EXCHSRV01 |? {$_.ActiveCopy -eq $true} | ft DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy -AutoSize
Get ALL non-healthy Passive COPIES on a Server
Get-MailboxDatabaseCopyStatus -Server EXCHSRV01 | where ({$_.Status -ne “healthy” -and $_.Status -ne “mounted” })| sort name |ft name, Status, LatestFullBackupTime, ActiveCopy -autosize
Get status for all copies of a particular database DB01
Get-MailboxDatabaseCopyStatus -Identity ‘DB01′ | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Get Status for all database copies on the Mailbox server EXCHSRV01 (extensive details)
Get-MailboxDatabaseCopyStatus -Server EXCHSRV01 | fl DatabaseName, Status, ActiveDatabaseCopy, ActivationSuspended, ContentIndexState, ContentIndexErrorMessage, ReplayQueueLength, LastCopiedLogTime, ErrorMessage
Get Database and Log Paths
Get-MailboxDatabase DB01 | fl *path*
Find Database Log file location
Get-MailboxDatabase DB01 | fl logfolderpath
See if Circular Enabled is enabled
Get-MailboxDatabase -Identity DB01 | fl Name, CircularLoggingEnabled
Check the Mount Status of a Mailbox Database
Get-MailboxDatabase -Status | Select Name, Server, Mounted
Dismount a Mailbox Database
Dismount-Database “DB01″
Get Local Database Status
Get-MailboxDatabaseCopyStatus -Local | fl DatabaseName, ContentIndexState, Status,CopyQueueLength,ContentIndexState,LatestFullBackupTime,ActiveCopy,ErrorEventID,errormessage
Status information for all copies of the database Ex10mbx01 and details
Get-MailboxDatabaseCopyStatus -Identity ‘Ex10mbx08′ | fl name, server, activationpreference,Status,CopyQueueLength,ContentIndexState,LatestFullBackupTime,ActiveCopy,ErrorEventID,errormessage
Status information for all copies of the databases in DAG and details
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where {$_.Status -ne $healthy}| fl name, server, Status, CopyQueueLength, ContentIndexState, LatestFullBackupTime, ActiveCopy,ErrorEventID,errormessage
Get ALL MOUNTED Mailbox Databases and Find the Active Servers and details
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | ? {$_.ActiveCopy -eq $true} | sort name | ft mailboxserver,DatabaseName, Status,ContentIndexState -autosize
Get All Database Copy
Get-MailboxDatabaseCopy
Move Database Path
Move-DatabasePath -Identity DB01 -EdbFilePath E:\db\Ex10mbx19.edb
Block all databases hosted on a server from Activating
Set-MailboxServer –identity EXCHSRV01 –DatabaseCopyAutoActivationPolicy Blocked
Test-ReplicationHealth cmdlet to test the health of replication for the Mailbox server Ex10CHM01
Test-ReplicationHealth -Identity EXCHSRV01
Keep record of PowerShell commands
Start-Transcript -Path c:\PS_logfile.txt
Script to Set Database Retention Defaults on all mailboxes
(get-mailbox -resultsize unlimited | Set-Mailbox -UseDatabaseRetentionDefaults $true)
Find Mailbox Rules
Get-InboxRule -Mailbox {User Mailbox}
Get Mailbox Database and Server Information
Get-Mailbox -Identity {User Mailbox} | fl Alias,PrimarySMTPAddress,Database,ServerName
Get Sizes of all Folders in Mailbox
Get-MailboxFolderStatistics “{User Mailbox}” | FL Date, Name, FolderPath, FolderType, ItemsInFolder, DeletedItemsInFolder, FolderSize, ItemsInFolderAndSubfolders, DeletedItemsInFolderAndSubfolders, FolderAndSubfolderSize
Find when Mailbox was Created
get-mailbox -Identity ‘{User Mailbox}’ | fl Name, LinkedMasterAccount,PrimarySMTPAddress,WhenChangedUTC,WhenCreatedUTC
Enable Protocols on Mailbox
Set-CASMailbox -Identity ‘{User Mailbox}’ -OWAEnabled:$true -POPEnabled:$true -MAPIBlockOutlookRpcHttp:$false -ImapEnabled:$true -MAPIEnabled:$true -ActiveSyncEnabled:$true
Get Mailbox with Attributes
get-mailbox -Identity ‘{User Mailbox}’ | fl Name,DisplayName,alias,LinkedMasterAccount,PrimarySMTPAddress,EmailAddresses,OrganizationalUnit,ServerName,Database,IsMailboxEnabled, CustomAttribute7,CustomAttribute15,ProtocolSettings,ExchangeGuid,RecipientTypeDetails,CustomAttribute1,CustomAttribute2,CustomAttribute3, CustomAttribute4,CustomAttribute5,CustomAttribute6,CustomAttribute7,CustomAttribute8,CustomAttribute9,CustomAttribute10,CustomAttribute11, CustomAttribute12,CustomAttribute13,CustomAttribute14,CustomAttribute15,WhenChangedUTC,WhenCreatedUTC
Get Mailbox with Some Attributes
get-mailbox -Identity ‘{User Mailbox}’ | fl DisplayName,alias,LinkedMasterAccount,PrimarySMTPAddress,EmailAddresses,OrganizationalUnit,ServerName,Database,IsMailboxEnabled,ProtocolSettings, ExchangeGuid,RecipientTypeDetails,CustomAttribute1,CustomAttribute2,CustomAttribute7,CustomAttribute8,CustomAttribute14,CustomAttribute15,WhenChangedUTC,WhenCreatedUTC
Get folder list and type within Mailbox
Get-MailboxFolderStatistics -identity ‘{User Mailbox}’ | FL Name, FolderPath, FolderType
Enable Protocols on Mailbox
Set-CASMailbox -Identity {User Mailbox} -OWAEnabled:$true -POPEnabled:$true -MAPIBlockOutlookRpcHttp:$false -ImapEnabled:$true -MAPIEnabled:$true -ActiveSyncEnabled:$true
Gets Count of how many accounts have Customattribute2 set
(get-mailbox | where {$_.customattribute2 -eq ‘{attribute description}’ }).count
Get Mailbox using ‘ANR’ (ambiguous name)
Get-Mailbox -anr John
Get-Mailbox with customized ‘LinkedMasterAccount’
get-mailbox | where {$_.LinkedMasterAccount -like “S-1-5-21*”}
Get Mailbox Details – Storage usage and Log in times
Get-MailboxStatistics -Identity ‘{User Mailbox}’ | FL DisplayName, StorageLimitStatus, TotalDeletedItemSize, TotalItemSize, ItemCount, LastLoggedOnUserAccount, LastLogoffTime, LastLogonTime
Get Details and Creation, Modified
get-mailbox -Identity ‘{User Mailbox}’ | fl Alias,PrimarySMTPAddress,LinkedMasterAccount,CustomAttribute2,RecipientTypeDetails,Database,ServerName,WhenChangedUTC,WhenCreatedUTC
Get Mailbox Quota
Get-Mailbox -Identity ‘{User Mailbox}’ | Fl *quota
Troubleshooting Mailbox DiskSpace
- Clear the catalog
- Move mailboxes found using this
- get-mailboxdatabase DB01 | get-mailboxstatistics | Sort TotalItemSize -descending | Select DisplayName, TotalItemSize
Get Details and Creation, Modified (for showing)
get-mailbox -Identity ‘{User Mailbox}’ | fl Alias,PrimarySMTPAddress,LinkedMasterAccount,CustomAttribute2,RecipientTypeDetails,WhenChangedUTC,WhenCreatedUTC
Move Requests in Progress
Get-MoveRequest –MoveStatus InProgress
Use this command to find all non-completed move requests and group them by target database:
Get-MoveRequest | ?{ $_.Status -ne “Completed” -and $_.Status -ne “CompletedWithWarning” } | group targetdatabase | sort Count -Descending
Hide from GAL
Get-Mailbox -identity “{User Mailbox}” | Set-Mailbox -HiddenFromAddressListsEnabled $true
UnHide from GAL
Get-Mailbox -identity “{User Mailbox}” | Set-Mailbox -HiddenFromAddressListsEnabled $false
Gets Target Address
Get-QADUser {user} | Select Name,ProxyAddresses
Create a csv file from Get-MailboxStatistics, but with the TotalItemSize in MB
“DisplayName,TotalItemSize(MB),ItemCount,StorageLimitSize,Database,LegacyDN” | out-file GMS.csv; get-mailbox -resultsize unlimited | Get-MailboxStatistics | foreach{$a = $_.DisplayName;$b=$_.TotalItemSize.Value.ToMB(); $c=$_.itemcount;$d=$_.storagelimitstatus;$e=$_.database;$f=$_.legacydn;”$a,$b,$c,$d,$e,$f”} | out-file name.csv -Append
Get all mailbox sizes
Get-MailboxStatistics | ft DisplayName, TotalItemSize, ItemCount | where {$_.ObjectClass –eq “Mailbox”}
Get all mailbox sizes and export
Get-MailboxStatistics | ft DisplayName, TotalItemSize, ItemCount | where {$_.ObjectClass –eq “Mailbox”} > c:\name.txt
Get Mailbox Size for User
Get-MailboxStatistics “{User Mailbox}” | ft DisplayName, TotalItemSize, ItemCount
Out of Office status
Get-MailboxAutoReplyConfiguration {User Mailbox}
Disable Out of Office
Set-MailboxAutoReplyConfiguration {User Mailbox} -AutoReplyState Disabled
Get- Mailbox WITH LIKE command
Get-Mailbox | where {$_.EmailAddresses -like “*{User Mailbox}*”}
Get Mail Contact
Get-MailContact -Identity ‘{User Mailbox}’ | fl DisplayName,ExternalEmailAddress,RecipientType,CustomAttribute2,CustomAttribute5,CustomAttribute6,WhenCreatedUTC,WhenChangedUTC
Get Out of Office Settings
Get-MailboxAutoReplyConfiguration {User Mailbox}
Disable Out of Office Settings
Set-MailboxAutoReplyConfiguration {User Mailbox} -AutoReplyState Disabled
Check Deleted and inbox size
Get-MailboxStatistics -Identity ‘{User Mailbox}’ | fl DisplayName,DeletedItemCount,ItemCount,LastLoggedOnUserAccount,LastLogoffTime,LastLogonTime,LegacyDN, MailboxGuid,ObjectClass,StorageLimitStatus,TotalDeletedItemSize,TotalItemSize,Database, ServerName,DatabaseName,OriginatingServer
Get the current size of the Recoverable Items, Deletions, Purges, Versions
Get-MailboxFolderStatistics “{User Mailbox}” -FolderScope RecoverableItems | Format-List Name,FolderAndSubfolderSize
Get the Disconnected Mailboxes for organization
Get-MailboxDatabase | Get-MailboxStatistics | where {$_.DisconnectReason -ne $null} | Sort-Object -Property DisplayName | ft displayname,database,disconnectreason,DisconnectDate -auto
Get ALL Quota Limits for user
Get-Mailbox -IDENTITY “{User Mailbox}” | FL *quota*
Get Archive Mailbox Size for user
get-mailboxstatistics “{User Mailbox}” –archive | FL
Delete email from all users mailboxes
$mbxes = Get-Mailbox -Server “*SERVER*” -resultsize unlimited
$mbxes | Search-Mailbox -SearchQuery ‘Subject:”*SUBJECT CONTAINS THIS*” Body:”*BODY CONTAINS THIS*”‘ -DeleteContent
If it doesn’t work and it works without the -DeleteContent part then it is a permission issue
If you want to run Search-Mailbox with parameter -DeleteContent, you must be assigned the “Mailbox import Export” Role.
Find the name of all folders in Mailbox
Get-MailboxFolderStatistics -Identity “mailbox alias” | ft Identity | more
Database Seeding cmdlets
Get Database Copy Status
Get-MailboxDatabaseCopyStatus -Identity ‘DB01′ | ft name,Status,ContentIndexState,ReplayQueueLength,CopyQueueLength -autosize
Status for all database copies on the Mailbox server EXCHSRV01 by status
Get-MailboxDatabaseCopyStatus -Server EXCHSRV01 | Sort-Object -Property Status| ft mailboxserver,DatabaseName, status,Copyqueuelength,Replayqueuelength, ContentIndexState, ActiveCopy,ErrorMessage -AutoSize
UPDATE Seed a copy of a database named DB02 on EXCHSRV01 using EXCHSRV02 as the source Mailbox server for the seed
Update-MailboxDatabaseCopy -Identity DB02\EXCHSRV01 -SourceServer EXCHSRV02
UPDATE Seed a copy of a database named DB02 on EXCHSRV01 using EXCHSRV02 as the source Mailbox server for the seed (remove existing files)
Update-MailboxDatabaseCopy -Identity DB02\EXCHSRV01 -sourceserver EXCHSRV02 -DeleteExistingFiles
Update the Database using a source server and delete existing files
Update-MailboxDatabaseCopy -Identity DB02\EXCHSRV01 -DeleteExistingFiles
Update ONLY the Database using a source server and delete existing files
Update-MailboxDatabaseCopy -Identity DB01\EXCHSRV01 -SourceServer EXCHSRV02 -DatabaseOnly -DeleteExistingFiles
Update Catalog Only
Update-MailboxDatabaseCopy -identity DB01\EXCHSRV01 –CatalogOnly
Update Database Only without seeding the content index catalog
Update-MailboxDatabaseCopy -identity DB01\EXCHSRV01 –Databaseonly
UPDATE the Catalog on DB01 on EXCHSRV01 using EXCHSRV02 as the source Mailbox server for the seed
Update-MailboxDatabaseCopy -Identity DB01\EXCHSRV01 -SourceServer EXCHSRV02 -catalogonly
Update-MailboxDatabaseCopy -Identity DB01\EXCHSRV01 -DeleteExistingFiles
Resume all Copies in FailedandSuspended
Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “FailedandSuspended”}| Resume-MailboxDatabaseCopy
Resume all Copies in Failed state on Server
Get-MailboxDatabase -server EXCHSRV01| Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed”}| Resume-MailboxDatabaseCopy
Resume Database Copy for all Databases located on Server
Get-MailboxDatabaseCopyStatus -Server EXCHSRV01 | Resume-Mailboxdatabasecopy
Resume-MailboxDatabaseCopy -Identity DB01\EXCHSRV01
Suspend Mailbox Database Copy
Suspend-MailboxDatabaseCopy -Identity DB01\EXCHSRV01 -SuspendComment “Maintenance ” -Confirm:$False
Suspend all Copies in Failed state on Server
Get-MailboxDatabase -server EXCHSRV01| Get-MailboxDatabaseCopyStatus | where {$_.Status -eq “Failed”}| Suspend-MailboxDatabaseCopy
Get-MailboxDatabaseCopyStatus -Server EXCHSRV01 | Suspend-MailboxDatabaseCopy
Add Mailbox Database Copy
Add-MailboxDatabaseCopy -Identity ‘DB01′ -MailboxServer ‘EXCHSRV09′
Add Mailbox Database Copy (SEEDING POSTPONED)
Add-MailboxDatabaseCopy -Identity DB04 -MailboxServer EXCHSRV09 -SeedingPostponed
MOVE ACTIVE DATABASE
Set Active Mailbox Database Copy
Move-ActiveMailboxDatabase -Identity ‘DB01′ -ActivateOnServer ‘EXCHSRV02′ -MountDialOverride ‘None’
Set Active Mailbox Database Copy with failed Catalog
Move-ActiveMailboxDatabase -Identity ‘DB01′ -ActivateOnServer ‘EXCHSRV02′ -MountDialOverride ‘None’ -SkipClientExperienceChecks
Remove Mailbox Database Copy
Remove-MailboxDatabaseCopy -Identity DB01\EXCHSRV01 -Confirm:$False
Context Index
Disable Indexing on Mailbox Database
Set-MailboxDatabase “DB01″ -IndexEnabled $false
Enable Indexing on Mailbox Database
Set-MailboxDatabase “DB03″ -IndexEnabled $true
Finding the passive Databases with Failed Index (can’t update the index on the active DB)
Get-MailboxServer | Get-MailboxDatabaseCopyStatus | ? {$_.Status -ne “Mounted” –and $_.ContentIndexState -eq “Failed”} | ft -autosize
Fix the Passive databases with Failed Index
Get-MailboxServer | Get-MailboxDatabaseCopyStatus | ? {$_.Status -ne “Mounted” –and $_.ContentIndexState -eq “Failed”} | Update-MailboxDatabaseCopy –CatalogOnly
Fix all Passive databases with Failed Index per Database
Get-MailboxDatabaseCopyStatus -identity DB01\* | ? {$_.Status -ne “Mounted” -and $_.ContentIndexState -eq “Failed”} | Update-MailboxDatabaseCopy -CatalogOnly
Exchange 2010 DAG Related
Get DAG Status
Get-DatabaseAvailabilityGroup {DAG NAME} -Status | fl
StartDagServerMaintenance.ps1 script to put the DAG member in maintenance mode
.\StartDagServerMaintenance.ps1 -serverName {DAG NAME}
StopDagServerMaintenance.ps1 script to take the DAG member out of maintenance mode
.\StopDagServerMaintenance.ps1 -serverName {DAG NAME}
Find DatabaseCopyAutoActivationPolicy for all Servers
Get-MailboxServer | Sort-Object -Property DatabaseCopyAutoActivationPolicy | ft name,DatabaseCopyAutoActivationPolicy -AutoSize
Get Maintenance Status
Get-DatabaseAvailabilityGroup {DAG NAME} -Status | fl Servers, ServersInMaintenance
Get ALL Databases and Active Preference information NEAT
Get-MailboxDatabase | Sort Name | ft Name,ActivationPreference -AutoSize
Get total number of Databases in Organzation
(Get-MailboxDatabase | Sort-Object -Property Servername Name | ft Name,ServerName,MountedOnServer, ActivationPreference).count
Get All databases and Activation Preference information
Get-MailboxDatabase | ft name, server, activationpreference -AutoSize
Get Specific databases and Activation Preference information
Get-MailboxDatabase -Identity {DB Name} | fl name, server, activationpreference
Get Primary Active Manager (PAM)
Get-DatabaseAvailabilityGroup -Identity {DAG NAME} -Status | fl name,primaryactivemanager
Move PAM to another server
cluster.exe {DAGname.Domain.com) group “cluster group” /moveto:{servername}
To block DB activation (switch site as needed)
Get-ExchangeServer | where { $_.Site -like ‘{ExchangeOrg.Domain.com/Configuration/Sites/SiteA’ } | Get-MailboxServer | Set-MailboxServer –DatabaseCopyAutoActivationPolicy Blocked
Enable DAC Mode
Set-DatabaseAvailabilityGroup –identity “{DAG NAME}” –DatacenterActivationMode DagOnly
Run RedistributeActiveDatabases.ps1 script to re-balance the active database copies across the DAG
.\RedistributeActiveDatabases.ps1 -DagName {DAG NAME} -BalanceDbsByActivationPreference -ShowFinalDatabaseDistribution -Confirm:$false > DagConfig.txt
Get Primary Active Manager
get-databaseavailabilitygroup –identity {DAG NAME} –status | fl name,primaryActiveManager
Remove Server from Dag
Remove-DatabaseAvailabilityGroupServer -Identity {DAG NAME} -MailboxServer EXCHM01
Add Server to DAG
ADD-DatabaseAvailabilityGroupServer -Identity {DAG NAME} -MailboxServer EXCHM04
Unblock all databases hosted on a server
Set-MailboxServer –identity {ServerName} –DatabaseCopyAutoActivationPolicy Unrestricted
Block all databases hosted on Server
Set-MailboxServer –identity {ServerName} –DatabaseCopyAutoActivationPolicy Blocked
Set Mailbox Database Copy Activation Copy
Set-MailboxDatabaseCopy -Identity {DB Name}\{ServerName} -ActivationPreference 1
To block a database copy from getting activated automatically
Suspend-MailboxDatabaseCopy –identity {DB Name}\{ServerName} –ActivationOnly
This is absolutely dead handy. Thank you. I’ve stolen most of these.
Thanks Jeff