Exchange powershell
Check here for other powershell commands for exchange:
Exchange Update
Exchange issues
Check the Database availability groups cmdlet - use to find out if exchange server is the Primary or Secondary
Get-DatabaseAvailabilityGroup
You can get all the details you need by using the following command:
Get-DatabaseAvailabilityGroup | fl
Get-DatabaseAvailabilityGroup -status
Sometimes the witness will fail, you can check the status of the witness by using the cluster resource cmdlet:
ipmo failoverclusters
Get-ClusterResource
This will tell you where the witness stores the file. If the DAG finds the resource unrelibale it might mark it as failed - you can restart this by using start-cluster resource:
Get-ClusterResource | Start-ClusterResource
Issue after update
If there are issues after updates run the script to rebuild OWA and ECP:Link to MS Learn article
Issues with mail queue:
use Exchange toolbox to open queue viewer
This will let you know if there are issues with incoming or outgoing emails.
Get info on server setup:
Get-TransportConfig
Get-TransportServer -Identity <servername> | fl
Show Database copy status between the exchange servers in a DAG:
Get-MailboxDatabaseCopyStatus <source lang="powershell"> | sort name | ft -autosize
Get Server that may be experiencing backpressure
Get-MailboxServer | foreach {Get-EventLog -ComputerName $_.Name -Source MSExchangeTransport -LogName Application -After (Get-Date).AddDays(-1) | where {$_.EventID -eq "15004"}}
Check for failed messages:
Get-MessageTrackingLog -Start "9/27/2021 13:00:00" -ResultSize unlimited | ? {$_.EventID -eq "Fail"}
Exchange Log Drive filling
Enable circular logging to flush transaction logs. This will mean you will not have the logs to perform a database restore
Go to Exchange Management Console and then go into Organization configuration, then Mailbox. On the database management tab there will be the databases. Click on the database and select properties, then in the maintenance tab click to enable circular logging.
Then Dismount and remount the database, this will clear the transaction logs.
Once logs have been cleared by mounting the database with circular logging enabled you should then dismount, disable circular logging and mount again. Then get the backups sorted.
Exchange Configuration
When setting up exchange for imap or pop make sure that the certificate is bound to the service
check all settings are configured using get-imapsettings
example of external connection setup command:
Set-ImapSettings -ExternalConnectionSettings "mail.contoso.com:993:SSL","mail.contoso.com:143:TLS" -X509CertificateName mail.contoso.com
Exchange Connectors
If throttling is occurring on a specific connector we can increase the allowed connections:
To check the current limit (20 by default), run the following cmdlet and look for MaxInboundConnectionPerSource:
Get-ReceiveConnector | Select *MaxInbound*
To increase the limit, you have to use the Exchange Management Shell:
Set-ReceiveConnector -MaxInboundConnectionPerSource 500 -MaxInboundConnectionPercentagePerSource 100
Send and receive connectors can be either frontend or hub transport.
SMTP Relay Connectors
For exchange 2016 relay connector will need to be frontend transport type connector
To allow for annomous relays you will need to add ad permissions to the relay connector:
Get-ReceiveConnector "EXSERVER\Anon Relay EXSERVER" | Add-ADPermission -User 'NT AUTHORITY\Anonymous Logon' -ExtendedRights MS-Exch-SMTP-Accept-Any-Recipient
Exchange Connector Certificate
When updating exchange certificate you may need to apply the new cert to the send connectors (Usually outbound to O365)
Get the exchange certificate and apply it to the connector:
$cert = Get-ExchangeCertificate -Thumbprint <new cert thumbprint>
$certname = "<i>$($cert.Issuer)<s>$($cert.Subject)"
Set-SendConnector -Identity <send connector identity> -TLSCertificateName $certname
Exchange search + Search Index
If search is not running in OWA or in exchange mailboxes check the search index on databases:
Get-MailboxDatabaseCopyStatus -Server <exchangeserver> | ft -auto
Get-MailboxDatabaseCopyStatus -Server <exchangeserver> | Where {$_.ContentIndexState -ne "Healthy"} | Select name,ContentIndexState,ContentIndexErrorMessage
Check exchange search services
Test exchange search:
Test-ExchangeSearch -MailboxDatabase DB02
Rebuild the Content Index if required, if server is in a DAG try to reseed from other database. if not: Stop exchange services:
Stop-Service MSExchangeFastSearch; Stop-Service HostControllerService
Delete the GUID-named folder that contains the content index files - this will be in the exchange databases folder and will be in a sub folder with a GUID for a name - you will need to delete the folder.
You can find the correct folder name using a script that is provided by Microsoft in the exchange program files scripts folder - getsearchindexfordatabase.ps1 eg:
Start the exchange services to rebuild the index:
Start-Service MSExchangeFastSearch; Start-Service HostControllerService
Doing the "Get-MailboxDatabaseCopyStatus -Server <exchangeserver> | ft -auto" command again will show you the status of the indexing
Exchange Migration - Hybrid
Error when moving mailboxes and need to run mailbox as a different migration batch? Remove the mailbox from the batch:
Get-MoveRequest -Identity 'tony@contoso.com'
Remove-MoveRequest -Identity 'tony@contoso.com'
Migrate Exchange Database to new location(will dismount database and move files to new location):
Move-databasepath -identity "Mailbox Database" -edbfilepath "I:\Mailbox Database\mailbox database.edb"