• Home
  • PowerShell
  • Enforcing password policy in Active Directory using PowerShell

Enforcing password policy in Active Directory using PowerShell

Step 1: View the current password policy

Check the current domain password policy settings using the script below. This displays the password length, complexity, and lockout settings.

Get-ADDefaultDomainPasswordPolicy

Step 2: Modify the password policy

Set a strong password policy by running the script below. This policy will require a minimum of 12 characters, enforce complex passwords, and lock accounts after five failed attempts.

Set-ADDefaultDomainPasswordPolicy -MinPasswordLength 12 -ComplexityEnabled $true -LockoutThreshold 5

Step 3: Apply fine-grained password policies

For different policies based on user roles, run the script below. This enforces stricter rules for admin accounts.

New-ADFineGrainedPasswordPolicy -Name "AdminsPolicy" -Precedence 1 -MinPasswordLength 15 -ComplexityEnabled $true -LockoutThreshold 3

Step 4: Assign policy to specific users or groups

Apply the policy to a specific group. This ensures that only admins follow this stricter policy.

Add-ADFineGrainedPasswordPolicySubject -Identity "AdminsPolicy" -Subjects "Domain Admins"

FAQs

1. How do I check the current password policy in AD?

Check the current password policy by running the script below. This returns the domain's default password settings.

Get-ADDefaultDomainPasswordPolicy

2. How do I enforce a stronger password policy?

Run the script below to enforce a stronger password policy. This sets 12-character complex passwords with lockout after five failed attempts.

Set-ADDefaultDomainPasswordPolicy -MinPasswordLength 12 -ComplexityEnabled $true -LockoutThreshold 5

3. Can I apply different password policies to different users?

Yes, this can be done using fine-grained password policies (FGPP).

 
  • Step 1: View the current password policy
  • Step 2: Modify the password policy
  • Step 3: Apply fine-grained password policies
  • Step 4: Assign policy to specific users or groups
  • FAQs

ADSelfService Plus trusted by

A single pane of glass for complete self service password management
Email Download Link