Thursday 11 June 2020

How to set Database Activation Preference number for a Database in Exchange server 2016

I was working in a project, had to migrate the Exchange Sever 2013 environment to Exchange 2016. The environment was consist of PR (4 servers) and DR (3 servers), Total of 30 databases.

At one point i had to play with the DAG failover/switchover, in which i found that every time i activate any of the DBs on any desired server, after some time (1-2 hours) the DBs automatically move/activate back on the first server in the PR site.

After looking into it more i noticed that the "ActivationPreference" value on that server was lowest, set to "1".
So as per the default behavior of the DAG, every time if there is any issue in the DAG/database copies, the DAG will activate the DB on the server which has the most healthy copy. If all the servers have the healthy copies then the copy on the server with the lowest "ActivationPreference" number , i.e "1", will be activated.

So now i have to change the "ActivationPreference" number of all the 30 DBs but you know from the ECP it was a lengthy task so i followed the following steps in the Exchange management shell and performed it very easily and in a very short time.

First i had to check the current status (ActivationPreference value) of each of the DB with the following command.

Get-MailboxDatabase service1603 | fl servers, ActivationPreference


Then i used the following command to set the "ActivationPreference" value as per my requirement.

Set-MailboxDatabaseCopy -identity ‘service1603\MBS03’ -ActivationPreference 1

To check/verify the changes use the following command again but it took some time to show the updated value but in ECP the update value was appearing. 

Get-MailboxDatabase service1603 | fl servers, ActivationPreference
so you should give it some time or check in ECP the updated values. 


Tuesday 9 June 2020

How to export last password reset date of Azure AD/office 365 users through powershell

To get the Azure AD or office 365 etc. last password reset date i use the following steps in windows powershell.
1)
login to Azure AD
$credential = Get-Credential

(once prompt for credentials, use your username/password i.e nawaz@mycompany.com/password)

Then you may use one of the following command to connect Azure AD.

2)
Connect-AzureAD -Credential $credential
OR
Connect-MsolService -Credential $credential

Now you should be connected with Azure AD, to confirm you may use type the first few characters of any Azure AD command and press Tab key, if the command showing any suggested command then it means you are connect.

3)
Get the required detail of one user and then get/use the same command for all users.
so lets use

PS C:\Windows\system32> Get-MsolUser -UserPrincipalName nawaz@mycommany.com | select displayname, lastpasswordchangetimestamp                                                                                                               
DisplayName                                                        LastPasswordChangeTimestamp
-----------                                                        ---------------------------
Nawaz Khan System engineer           2/26/2020 7:59:58 AM

Now that we got the desired details for a single user, so we can use the same command, just replacing the -UserPrincipalName with -all switch and exporting the output to a CSV.

Get-MsolUser -All | select DisplayName,LastPasswordChangeTimeStamp >c:\path\LastPasswordChangeDate.csv

Now you may have to wait for the command to complete, it may get time to complete, as per your number of users in Azure.

Friday 5 June 2020

How to move multiple databases with a single command to another mailbox server in Exchange Server 2016

Some time you may have to activate a group of DBs on a server, then you have 2 option to perform this task, 1 is from ECP but it will take some long time if you have some multiple DBs. Second option is to use Exchange management shell, which will save your time and also will perform this task very easily.
So you can perform the following command in exchange management shell.
for example you have 4 DBs, all end with 01 numbers, which you want to be activated on MBS01 server.



Get-MailboxDatabase *601 | Move-ActiveMailboxDatabase -ActivateOnServer MBS01

To verify you can use the following command
Get-MailboxDatabase *601

[PS] C:\Windows\system32>Get-MailboxDatabase *1601
Name                           Server          Recovery        ReplicationType
----                           ------          --------        ---------------
HR1601                     MBS01  False           Remote
IT1601                     MBS01  False           Remote
M1601                     MBS01  False           Remote
P1601                     MBS01  False           Remote

So we can see here that all the required DBS are activated on MBS01 with a single command.

Thursday 4 June 2020

How to register Exchange server 2016 keys with powershell

Some time you may be unable to enter the Exchange server 2016 product key from ECP/EAC.
As i faced the same. i migrated an exchange environment from exchange server 2013 to exchange 2016. the ECP was still pointing to the exchange server 2013 CAS server. so when i tried to enter the product from ECP i was getting an error like as below

"An error occurred while accessing the registry on the server "Servername". The error that occurred is: "The network path was not found. "."

And the reason might be that the virtual directory i.e (https://mail.domain.com/ECP) was still pointing to the 2013 CAS servers.

So then i tried to put/enter the key through power shell as below and i was able to register the server in this way.
  
Set-ExchangeServer -Identity ServerName -ProductKey 8JHUYI-JHUYM-VNMFE-FGHJY-HJYUTV

So per my experience, if you want to register the key for the 2016 through ECP (https://mail.domain.com/ECP), your required virtual directory should be pointing to that 2016 environment/server.