Exchange: Difference between revisions

From Piszczynski
piszczynski>Aleks
No edit summary
 
(11 intermediate revisions by 2 users not shown)
Line 4: Line 4:


https://piszczynski.com/ExchangePowershell
https://piszczynski.com/ExchangePowershell
== Exchange Update ==
[https://learn.microsoft.com/en-us/exchange/plan-and-deploy/install-cumulative-updates?view=exchserver-2019#what-do-you-need-to-know-before-you-begin Exchange CU update article]
== Exchange issues ==
== Exchange issues ==


Check the Database availability groups cmdlet - use to find out if exchange server is the Primary or Secondary  
Check the Database availability groups cmdlet - use to find out if exchange server is the Primary or Secondary  


*Get-DatabaseAvailabilityGroup
<source lang="powershell">Get-DatabaseAvailabilityGroup</source>


You can get all the details you need by using the following command:
You can get all the details you need by using the following command:


*Get-DatabaseAvailabilityGroup | fl
<source lang="powershell">Get-DatabaseAvailabilityGroup | fl</source>


*Get-DatabaseAvailabilityGroup -status
<source lang="powershell">Get-DatabaseAvailabilityGroup -status</source>


Sometimes the witness will fail, you can check the status of the witness by using the cluster resource cmdlet:
Sometimes the witness will fail, you can check the status of the witness by using the cluster resource cmdlet:


*ipmo failoverclusters
<source lang="powershell">ipmo failoverclusters</source>


*Get-ClusterResource
<source lang="powershell">Get-ClusterResource</source>


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:
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
<source lang="powershell">Get-ClusterResource | Start-ClusterResource</source>
 
=== Issue after update ===
If there are issues after updates run the script to rebuild OWA and ECP:[https://learn.microsoft.com/en-us/exchange/troubleshoot/client-connectivity/owa-stops-working-after-update Link to MS Learn article]
 
----
----
Issues with mail queue:
Issues with mail queue:
*use Exchange toolbox to open queue viewer
<source lang="powershell">use Exchange toolbox to open queue viewer</source>


This will let you know if there are issues with incoming or outgoing emails.
This will let you know if there are issues with incoming or outgoing emails.
----
----
Get info on server setup:
Get info on server setup:
*Get-TransportConfig
<source lang="powershell">Get-TransportConfig</source>
*Get-TransportServer -Identity <servername> | fl
<source lang="powershell">Get-TransportServer -Identity <servername> | fl</source>
----
----
Show Database copy status between the exchange servers in a DAG:
Show Database copy status between the exchange servers in a DAG:
*Get-MailboxDatabaseCopyStatus * | sort name | ft -autosize
<source lang="powershell">Get-MailboxDatabaseCopyStatus <source lang="powershell"> | sort name | ft -autosize</source>
----
----
Get Server that may be experiencing backpressure
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"}}
<source lang="powershell">Get-MailboxServer | foreach {Get-EventLog -ComputerName $_.Name -Source MSExchangeTransport -LogName Application -After (Get-Date).AddDays(-1) | where {$_.EventID -eq "15004"}}</source>
----
----
Check for failed messages:
Check for failed messages:
*Get-MessageTrackingLog  -Start "9/27/2021 13:00:00" -ResultSize unlimited | ? {$_.EventID -eq "Fail"}
<source lang="powershell">Get-MessageTrackingLog  -Start "9/27/2021 13:00:00" -ResultSize unlimited | ? {$_.EventID -eq "Fail"}</source>


== Exchange Log Drive filling ==
== Exchange Log Drive filling ==
Line 62: Line 70:


example of external connection setup command:
example of external connection setup command:
*Set-ImapSettings -ExternalConnectionSettings "mail.contoso.com:993:SSL","mail.contoso.com:143:TLS" -X509CertificateName mail.contoso.com
<source lang="powershell">Set-ImapSettings -ExternalConnectionSettings "mail.contoso.com:993:SSL","mail.contoso.com:143:TLS" -X509CertificateName mail.contoso.com</source>
 


== Exchange Connectors ==
== Exchange Connectors ==


If throttling is occuring on a specific connector we can increase the allowed connections:
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.  
To check the current limit (20 by default), run the following cmdlet and look for MaxInboundConnectionPerSource:<syntaxhighlight lang="powershell">
Get-ReceiveConnector | Select *MaxInbound*
</syntaxhighlight>To increase the limit, you have to use the Exchange Management Shell:<syntaxhighlight lang="powershell">
Set-ReceiveConnector -MaxInboundConnectionPerSource 500 -MaxInboundConnectionPercentagePerSource 100
</syntaxhighlight>Send and receive connectors can be either frontend or hub transport.  


----
----
Line 82: Line 87:
For exchange 2016 relay connector will need to be frontend transport type connector
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:
To allow for annomous relays you will need to add ad permissions to the relay connector:<syntaxhighlight lang="powershell">
*Get-ReceiveConnector "EXSERVER\Anon Relay EXSERVER" | Add-ADPermission -User 'NT AUTHORITY\Anonymous Logon' -ExtendedRights MS-Exch-SMTP-Accept-Any-Recipient
Get-ReceiveConnector "EXSERVER\Anon Relay EXSERVER" | Add-ADPermission -User 'NT AUTHORITY\Anonymous Logon' -ExtendedRights MS-Exch-SMTP-Accept-Any-Recipient
</syntaxhighlight>


===Exchange connector Certificate===
===Exchange Connector Certificate===
When updating exchange certificate you may need to apply the new cert to the send connectors (Usually outbound to O365)
When updating exchange certificate you may need to apply the new cert to the send connectors (Usually outbound to O365)


Get the exchange certificate:
Get the exchange certificate and apply it to the connector:<syntaxhighlight lang="powershell" line="1">
*$cert = Get-ExchangeCertificate -Thumbprint <new cert thumbprint>
$cert = Get-ExchangeCertificate -Thumbprint <new cert thumbprint>
**$certname = "<i>$($cert.Issuer)<s>$($cert.Subject)"
$certname = "<i>$($cert.Issuer)<s>$($cert.Subject)"
***Set-SendConnector -Identity <send connector identity> -TLSCertificateName $certname
Set-SendConnector -Identity <send connector identity> -TLSCertificateName $certname
</syntaxhighlight>


== Exchange search + Search Index ==
== Exchange search + Search Index ==


If search is not running in OWA or in exchange mailboxes check the search index on databases:
If search is not running in OWA or in exchange mailboxes check the search index on databases:<syntaxhighlight lang="powershell" line="1">
*Get-MailboxDatabaseCopyStatus -Server <exchangeserver> | ft -auto
Get-MailboxDatabaseCopyStatus -Server <exchangeserver> | ft -auto
**Get-MailboxDatabaseCopyStatus -Server <exchangeserver> | Where {$_.ContentIndexState -ne "Healthy"} | Select name,ContentIndexState,ContentIndexErrorMessage
Get-MailboxDatabaseCopyStatus -Server <exchangeserver> | Where {$_.ContentIndexState -ne "Healthy"} | Select name,ContentIndexState,ContentIndexErrorMessage
 
</syntaxhighlight>
----
----
Check exchange search services
Check exchange search services


Test exchange search:
Test exchange search:
*Test-ExchangeSearch -MailboxDatabase DB02
<syntaxhighlight lang="powershell">Test-ExchangeSearch -MailboxDatabase DB02</syntaxhighlight>
 
----
----
Rebuild the Content Index if required, if server is in a DAG try to reseed from other database. if not:
Rebuild the Content Index if required, if server is in a DAG try to reseed from other database. if not:
Stop exchange services:
Stop exchange services:
*Stop-Service MSExchangeFastSearch; Stop-Service HostControllerService
<syntaxhighlight lang="powershell">Stop-Service MSExchangeFastSearch; Stop-Service HostControllerService</syntaxhighlight>
 


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.
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:
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:
*.\getsearchindexfordatabase.ps1 mailbox
<syntaxhighlight lang="powershell".\getsearchindexfordatabase.ps1 mailbox></syntaxhighlight>
 


Start the exchange services to rebuild the index:
Start the exchange services to rebuild the index:
*Start-Service MSExchangeFastSearch; Start-Service HostControllerService
<syntaxhighlight lang="powershell">Start-Service MSExchangeFastSearch; Start-Service HostControllerService</syntaxhighlight>
 


Doing the "Get-MailboxDatabaseCopyStatus -Server <exchangeserver> | ft -auto" command again will show you the status of the indexing
Doing the "Get-MailboxDatabaseCopyStatus -Server <exchangeserver> | ft -auto" command again will show you the status of the indexing
Line 122: Line 133:


Error when moving mailboxes and need to run mailbox as a different migration batch? Remove the mailbox from the batch:
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'
<syntaxhighlight lang="powershell" line>Get-MoveRequest -Identity 'tony@contoso.com'
*Remove-MoveRequest -Identity 'tony@contoso.com'
Remove-MoveRequest -Identity 'tony@contoso.com'</syntaxhighlight>
 
 
Migrate Exchange Database to new location(will dismount database and move files to new location):
<syntaxhighlight lang="powershell">Move-databasepath -identity "Mailbox Database" -edbfilepath "I:\Mailbox Database\mailbox database.edb"</syntaxhighlight>

Latest revision as of 16:40, 18 January 2024

Exchange powershell

Check here for other powershell commands for exchange:

https://piszczynski.com/ExchangePowershell

Exchange Update

Exchange CU update article

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"