Note
These commands require the Active Directory PowerShell module:
| OS | Installation |
|---|---|
| Windows Server | Install-WindowsFeature RSAT-AD-PowerShell |
| Windows | Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0 |
-
Retrieve domain information:
Get-ADForest Get-ADDomain
-
List all domain controllers:
Get-ADDomainController -Filter *
-
Force synchronization between all domain controllers:
repadmin /syncall /AeP
-
Verify replication health with no replication latencies:
repadmin /replsummary
Tip
In case a secondary DC (e.g., KVM-DC02) has been offline for too long (typically more than a week) and encounters authentication issues during sync, follow these steps to restore the connection:
-
On the secondary DC, open Registry Editor.
-
Navigate to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NTDS\Parameters. -
Create a new DWORD (32-bit) Value:
Field Value Name Replication Authenticator CompatibilityValue 1 -
Attempt the replication command again:
repadmin /syncall /AeP. -
Once successful, delete the registry key to return to standard security protocols.
-
List all computers in the domain:
Get-ADComputer -Filter * | Select-Object Name, Enabled, ObjectClass
-
Join a computer to a domain:
Add-Computer -DomainName "khangvum.lab" -Server "<IP_ADDRESS>" -Credential "khangvum\<USERNAME>" -Restart -Verbose
-
Move a computer to an OU:
Move-ADObject -Identity "CN=<HOSTNAME>,CN=Computers,DC=khangvum,DC=lab" -TargetPath "OU=<OU>,DC=khangvum,DC=lab"
-
Create a new user:
New-ADUser -Name "<FULL_NAME>" ` -GivenName "<FIRST_NAME>" ` -Surname "<LAST_NAME>" ` -DisplayName "<FULL_NAME>" ` -SamAccountName "<USERNAME>" ` -UserPrincipalName "<USERNAME>@<DOMAIN>" ` -EmailAddress "<USERNAME>@<DOMAIN>" ` -Path "CN=Users,DC=khangvum,DC=lab" ` -AccountPassword (Read-Host -AsSecureString "Enter Password") ` -Enabled $true
-
Reset user password:
Set-ADAccountPassword -Identity "<USERNAME>" -Reset -NewPassword (Read-Host -AsSecureString "Enter New Password")
-
Enable/Disable a user:
# Enable a user Enable-ADAccount -Identity "<USERNAME>" # Disable a user Disable-ADAccount -Identity "<USERNAME>"
-
Unlock a user:
Unlock-ADAccount -Identity "<USERNAME>"
-
View current password policy:
Get-ADDefaultDomainPasswordPolicy -
Modify domain password policy:
Set-ADDefaultDomainPasswordPolicy -Identity (Get-ADDomain).DNSRoot ` -MaxPasswordAge "00:00:00" ` -MinPasswordAge "00:00:00" ` -PasswordHistoryCount 5