35 C
Dubai
Saturday, May 3, 2025
Home Blog Page 25

How to Promote Windows Server as a Domain Controller

No more DCPromo, Just add roles and you can promote as a Domain Controller

Article Supports Windows Server 2016 and 2019

Using Powershell

Rename Computer –

Rename-Computer -NewName AD001 -Restart

Rename Domain Name as per your requirements in below commands-

Add-WindowsFeature AD-Domain-Services -IncludeManagementTools
Install-ADDSForest -DomainName "Azure365pro.com" -InstallDNS

Active Directory Domain is ready.

Using GUI –

Lets See how to do it

Open Server Manager

image

Choose Add Roles and Features

image

Choose Role-Bases or Feature-Based installation

image

Make Sure it reflects the right Ip address . If it doesn’t Close Server manager and Reopen it

image

Choose Active Directory Domain Services

image

Choose Next

image

Choose Install

image

Choose Close

image

Now Roles are Added but , Its not a Domain Controller Yet

Click on More or the Flag

image

Choose Promote this Server to a Domain Controller

image

Am Building a new forest

Choosing _ Add a New forest

image

It does have Function level of Windows Server 2003 to Windows Server 2012

image

you can Skip it.

If you are Curious See –

What is DNS Delegation

image

Choose the NetBios Name

image

Leave it as default

image

If you are planning to promote more Domain Controllers , You can Use a Script like below

Which will give us more ease of deployment

image

Now to Access your Active Directory Services. use the Windows Start Button to access the features

image

Pin the important ones to start menu. So that it will be easily accessible for you

Connecting to PowerShell Online

  • Exchange Online PowerShell (Exchange Settings)
  • Azure Active Directory MSOnline (msol cmdlets)
  • Azure Active Directory PowerShell for Graph (azuread cmdlets)
  • Virtual Machine settings using Powershell (AzureRM cndlets)

PowerShell Capabilities are limitless with these modules you can automate most of the repetitive activities with ease.

Exchange Online PowerShell (Connect-ExchangeOnline)

Exchange Online PowerShell allows you to Exchange Online settings using a command line. You can manage all bulk changes using scripts and with a variety of commands using pipeline methods.

image

Let’s see how to Connect Exchange Online PowerShell

Set-ExecutionPolicy RemoteSigned
image
Install-Module PowershellGet -Force
Install-Module -Name ExchangeOnlineManagement
Connect-ExchangeOnline

Sample Command to make sure it’s connected.

image

You can explore the commands available using

get-command

it supports wildcards

image

Connecting to Office 365 PowerShell

Mostly to manage azure active directory users

Microsoft Azure Active Directory Module for Windows PowerShell (cmdlets include MSol in their name)

Install-Module MSOnline
image
Connect-MsolService
image

Sample Command to make sure its connected.

Get-MsolUser -UserPrincipalName user@domain.com
image

Azure Active Directory PowerShell for Graph (cmdlets include AzureAD in their name)

Install-Module -Name AzureAD
image
image
Connect-AzureAD
image
Get-AzureADDomain -Name azure365pro.com
image

To Get Virtual Machine settings using Powershell and AzureRM commandlets

Install-Module AzureRM
image
Connect-AzurermAccount
image

Sample Command to make sure it’s connected.

Get-AzureRmVM
image

Please note that if you don’t kill your session. You may need to wait until the power shell session expires if you reconnect multiple times.

Remove-PSSession $Session

Enable Remote Mailbox and Archive using CSV

To Export Specific OU for example to Enable Remote mailboxes

Get-ADuser -SearchBase "Distingushedname" -filter *  | Select-Object samaccountname,userprincipalname | Export-csv userdump.csv

Take CSV and replace user principal name with remote routing address. if you wish to populate remote mailboxes for a specific Organizational Unit. Make sure you replace it with your appropriate remote routing address specific to your Office 365 tenant.

Import-Csv EnableRemoteMailboxes.csv | ForEach-Object{new-RemoteMailbox -Identity $_.samaccountname -remoteroutingaddress $_.userprincipalname}

Use the Attached CSV. Fill with samaccountname and enable archive mailboxes in bulk

Import-Csv accounts.csv | ForEach-Object{Enable-RemoteMailbox -Identity $_.samaccountname -Archive}

Always specify remote routing address while enabling remote mailboxes otherwise powershell will throw up the below error.

The error – for the purposes of people searching for it is The Address @tenantname.mail.onmicrosoft.com is invalid: “@tenantname.mail.onmicrosoft.com” isn’t a valid SMTP address.
The domain name can’t contain spaces and it has to have a prefix and a suffix, such as example.com. 
FullyQualifiedErrorID : F0109C5E,Microsoft.Exchange.Management.Recipient.Tasks.EnableRemoteMailbox.

Synchronizing User must change password at next logon flag to Azure AD

Azure AD Connect does not synchronize the “User must change password at next logon” attribute from your on-premise Active Directory by default forcing users to update their new passwords through Azure Active Directory.

To enable this your directory you have some basic requirements of enabling Password Writeback in your Azure AD Connect Settings. which allows your news password set on Azure AD to sync back to your on-premises Active Directory. As you know enabling Self Service Password Reset (SSPR) will allow the user to reset the password on their own.

On the Azure AD Connect Server, Open PowerShell and run Get-ADSyncAADCompanyFeature to check if the ForcePasswordChangeOnLogOn has been set.

Get-ADSyncAADCompanyFeature | fl

To Enable it, you can use the below command.

Set-ADSyncAADCompanyFeature -ForcePasswordChangeOnLogOn $true

There was a flaw in this configuration which is fixed from Azure AD Connect 2.03

“Passwords will now be reevaluated when an expired password is “unexpired”, regardless of whether the password itself is changed. If for a user the password is set to “Must change password at next logon”, and this flag is cleared (thus “unexpiring” the password) then the “unexpired” status and the password hash are synced to Azure AD, and when the user attempts to sign in in Azure AD they can use the unexpired password.”

As you see if you set this flag (change password at next logon ) and un-set this flag. The unexpired password will not be synced to Azure Active Directory before. which is not the case from Azure AD Connect 2.0.3. When you uncheck, the same password is synced and retained in Azure Active Directory. As you know Azure AD Connect 2.0.3 requires Windows Server 2016 or above.
you can follow Upgrading Azure AD Connect to the latest version if you are running an older version.

Azure RADIUS based MFA not working with VPN

Users are not able to authenticate to VPN using Azure Multi-Factor Authentication while working outside the office. We found certificate provided for automatic NPS by Azure MFA Extension requires re-registration from azure active directory tenant.

Technology:                Azure AD Multi-Factor Authentication

Servers Involved:       NPS, Active Directory, Certificate Authority

Tools Utilized:             NPS Azure MFA Extension, PowerShell Module

Activity Followed to diagnose and provide a solution for the case is described below:

Analyzed the NPS event logs for Authentication, Identified the issues for user rejection on Azure MFA

Found the certificate from the azure tenant is not renewed automatically.

Removed the Azure AD Tenant certificate from NPS manually and created a new client certificate template from CA for regeneration of client certificate where Azure tenant can check the activity of the client.

Reinstalled the MFA extension on the NPS server

After Reinstalling the NPS Azure MFA extension, Installed all the required Repository for PowerShell modules which can lead us t register the NPS server again with azure active directory tenant

  • Below are the Scripts, we performed.
PS C:\Program Files\Microsoft\AzureMfa\Config> Register-PSRepository -Name PSGallery1 -SourceLocation https://www.powershellgallery.com/api/v2/ -InstallationPolicy Trusted
PS C:\Program Files\Microsoft\AzureMfa\Config> Set-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2/ -InstallationPolicy Trusted
PS C:\Program Files\Microsoft\AzureMfa\Config> Get-PSRepository

Name                InstallationPolicy     SourceLocation
----                      ------------------            --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2
PSGallery1                Trusted              https://www.powershellgallery.com/api/v2/

Deleted the untrusted PowerShell repository

PS C:\Program Files\Microsoft\AzureMfa\Config> Unregister-PSRepository -Name "PSGallery"
PS C:\Program Files\Microsoft\AzureMfa\Config> Get-PSRepository

Name                 InstallationPolicy        SourceLocation
----                      ------------------               --------------
PSGallery1                Trusted                  https://www.powershellgallery.com/api/v2/

Ran the MFA extension script to pull the certificate from azure ad

PS C:\Program Files\Microsoft\AzureMfa\Config> .\AzureMfaNpsExtnConfigSetup.ps1

Authenticated with the same key and id

PS C:\Program Files\Microsoft\AzureMfa\Config> .\AzureMfaNpsExtnConfigSetup.ps1
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2/' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='MSOnline'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'MSOnline'.
VERBOSE: Performing the operation "Install-Module" on target "Version '1.1.183.57' of module 'MSOnline'".
VERBOSE: The installation scope is specified to be 'AllUsers'.
VERBOSE: The specified module will be installed in 'C:\Program Files\WindowsPowerShell\Modules'.
WARNING: Version '1.1.183.17' of module 'MSOnline' is already installed at 
'C:\Program Files\WindowsPowerShell\Modules\MSOnline\1.1.183.17'. To install version '1.1.183.57', run Install-Module and add the -Force parameter, this command will install version '1.1.183.57' in side-by-side with version '1.1.183.17'.
Connecting to Microsoft Azure.  Please sign on as a tenant administrator.
Starting Azure MFA NPS Extension Configuration Script
Tenant ID currently registered with Azure MFA NPS Extension is: aa5e***9-d6d3-47d2-8848-*****
Enter new Tenant ID to change or press Enter to keep the current value:
Generating client certificate

Thumbprint                        Subject
----------                                -------
6F0E906DE97D71FBBCCB0DFEE9937A400F4B27CA  CN= aa5e***9-d6d3-47d2-8848-*****, OU=Microsoft NPS Extension
Client Certificate successfully generated
Client Certificate associated with Service Principal: 98**6a1-7f43-403b-*****
Starting registry updates
Completed registry updates
Client certificate : CN= aa5e***9-d6d3-47d2-8848-*****, OU=Microsoft NPS Extension successfully associated with Azure MFA NPS Extension for Tenant ID aa5e***9-d6d3-47d2-8848-*****
Granting certificate private key access to NETWORK SERVICE
Successfully granted to NETWORK SERVICE
Restarting Network Policy Server (ias) service
WARNING: Waiting for service 'Network Policy Server (ias)' to stop...
WARNING: Waiting for service 'Network Policy Server (ias)' to stop...
Configuration complete.  Press Enter to continue...:

you can see the Client Certificate successfully generated.

Client Certificate successfully generated
Client Certificate associated with Service Principal: 98**6a1-7f43-403b-*****

Re-registered the NPS server for a connection establishment with DC where the new establishment is connected successfully and obtained with active directory registration

New azure MFA Tenant certificate generated successfully and registered with Azure AD Tenant.

Users started receiving Azure Multi-Factor Authentication Prompts.

Upgrading Azure AD Connect to latest version

Upgrading Azure AD Connect 2.0 brings you the below benefits. if you are running on Windows Server 2012 R2 you need to do a swing migration As it doesn’t support Windows 2012 R2 anymore. below steps covers an in-place upgrade on Windows Server 2016 where TLS 1.2 is not enabled by default.

Download Azure AD Connect

  • TLS 1.2
  • All binaries signed with SHA2 and not SHA1
  • SQL Libraries updated from 2012 to SQL Server 2019 LocalDB

if TLS 1.2 is not enabled, let’s enable it using the below script and reboot the server.

Enable TLS 1.2 by saving below to ps1 fine and open the PowerShell as administrator and run it as below. Make sure you have a backup or a snapshot before you do these changes.


New-Item 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319' -name 'SystemDefaultTlsVersions' -value '1' -PropertyType 'DWord' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319' -name 'SchUseStrongCrypto' -value '1' -PropertyType 'DWord' -Force | Out-Null

New-Item 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319' -name 'SystemDefaultTlsVersions' -value '1' -PropertyType 'DWord' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319' -name 'SchUseStrongCrypto' -value '1' -PropertyType 'DWord' -Force | Out-Null

New-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server' -name 'Enabled' -value '1' -PropertyType 'DWord' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server' -name 'DisabledByDefault' -value 0 -PropertyType 'DWord' -Force | Out-Null

New-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client' -name 'Enabled' -value '1' -PropertyType 'DWord' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client' -name 'DisabledByDefault' -value 0 -PropertyType 'DWord' -Force | Out-Null
Write-Host 'TLS 1.2 has been enabled.'

Disable TLS 1.2


New-Item 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319' -name 'SystemDefaultTlsVersions' -value '0' -PropertyType 'DWord' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319' -name 'SchUseStrongCrypto' -value '0' -PropertyType 'DWord' -Force | Out-Null

New-Item 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319' -name 'SystemDefaultTlsVersions' -value '0' -PropertyType 'DWord' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319' -name 'SchUseStrongCrypto' -value '0' -PropertyType 'DWord' -Force | Out-Null

New-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server' -name 'Enabled' -value '0' -PropertyType 'DWord' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server' -name 'DisabledByDefault' -value 1 -PropertyType 'DWord' -Force | Out-Null

New-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client' -name 'Enabled' -value '0' -PropertyType 'DWord' -Force | Out-Null

New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client' -name 'DisabledByDefault' -value 1 -PropertyType 'DWord' -Force | Out-Null
Write-Host 'TLS 1.2 has been disabled.'

Save to .\EnableTLS1.2.ps1 and run it.

Reboot the server. Re-run the setup to detect TLS 1.2 and Upgrade.

Upgrading the synchronization engine

You don’t need a global administrator anymore where a new role is introduced (Hybrid Identity Administrator) which can be used for delegation.

use your global administrator or Hybrid Identity Administrator

Click Upgrade.

Configuration is complete.

There was a flaw where the password at the next logon is unchecked it doesn’t sync the unexpired password which is fixed from Azure AD Connect 2.03
“Passwords will now be reevaluated when an expired password is “unexpired”, regardless of whether the password itself is changed. If for a user the password is set to “Must change password at next logon”, and this flag is cleared (thus “unexpired” the password) then the “unexpired” status and the password hash are synced to Azure AD, and when the user attempts to sign in in Azure AD they can use the unexpired password.”
if you wish to Synchronizing User must change the password at the next logon flag to Azure AD

× How can I help you?