How to audit Active Directory Password Quality using PowerShell

The PowerShell script given below canbe used to list out all the domain user accounts with weak passwords in the Password Quality Report. The weak passwords are determined based on a predefined list, duplicate passwords, default passwords set by the administrator, and empty passwords. Alternatively you can also get the desired information without a PowerShell script using Weak Password Finder, a free tool offered by ManageEngine that finds and displays a list of users with weak passwords. ADSelfService Plus's Password Policy Enforcer helps you create a custom, stringent password policy thereby preventing the creation of weak passwords. Here is a comparison between auditing password quality of the domain accounts using PowerShell and ADSelfService Plus:

With PowerShell

To create this script the DSInternals module must be downloaded form GitHub. It's Test-PasswordQuality function is used to audit the user accounts' password quality.

Run the below PowerShell script to install the DSInternals module:

Install-Module DSInternals

Then create a text file with a list of weak passwords. Enter and run the PowerShell script provided below to generate the Password Quality Report.

$Passwords = "$($ENV:USERProfile)\Desktop\passwords.txt"

$Params = @{
"All" = $True
"Server" = 'DC'
"NamingContext" = 'dc=techsnips,dc=local'
}

Get-ADReplAccount @Params | Test-PasswordQuality -WeakPasswordsFile $Passwords -IncludeDisabledAccounts
With ADSelfService Plus

The Weak Password Finder helps you audit the password quality of user accounts in Active Directory by comparing users’ passwords against a pre-defined list of over commonly used weak passwords and generating a Weak Password Users Report as shown below:

Feature configuration is as simple as:

Apart from helping you find users with weak passwords, ADSelfService Plus' Password Policy Enforcer can also be used to create a customized password policy with rules for preventing dictionary passwords, patterns, and more for users accounts in specific domains, groups or OUs.

Advantages of ADSelfService Plus:

  • Quick configuration: With ADSelfService Plus, you are just a few clicks away from auditing the password quality of user accounts and preventing the creation of weak passwords. But in PowerShell, you need to create, debug and run scripts.
  • Compare passwords with an extensive list of weak passwords: The Weak Password Finder tool contains a pre-defined list of over 100,000 commonly used weak passwords. Administrators can add other passwords that are considered to be common or weak to this list. On the other hand, in PowerShell, administrators need to create a list of weak passwords and mention its file path in the script
  • Detailed and exportable reports: The Weak Password Users Report displays other user information such as sAMAccountName, department, OU, group and more. The report can also be exported as a CSV file. With PowerShell, the report will only display the user account's display name.
  • Creating stringent password policies: In ADSelfService Plus, customized password policies can be created with ease. The password policy rules that can be set include maximum password length, disallowing the use of dictionary words and palindrome, and specifying the minimum number of numeric characters, special characters, lowercase letters or uppercase letters to be included. PowerShell can also be used to create such rules but it requires extensive scripting knowledge.

Using PowerShell to audit AD password quality

Step 1: Retrieve users with weak passwords

Identify users with non-complex passwords. The script below lists accounts with no password requirement enabled.

Get-ADUser -Filter * -Properties PasswordLastSet, PasswordNotRequired | Where-Object { $_.PasswordNotRequired -eq $true }

Step 2: Find stale passwords

Check accounts with passwords older than 180 days. The script below identifies users who haven't changed their password in six months.

$staleUsers = Get-ADUser -Filter {PasswordLastSet -lt (Get-Date).AddDays(-180)} -Properties PasswordLastSet

Step 3: Generate a password audit report

Export the list to a CSV file. This saves weak password data to a CSV for further analysis.

$staleUsers | Select-Object Name, SamAccountName, PasswordLastSet | Export-Csv -Path "C:\Reports\PasswordAudit.csv" -NoTypeInformation

Step 4: Enforce password changes for weak accounts

Prompt affected users to reset passwords.

foreach ($user in $staleUsers) {
Set-ADUser -Identity $user.SamAccountName -ChangePasswordAtLogon $true
}

FAQs

1. How do I check the strength of AD passwords?

You can check the strength of AD passwords by running the script below. This retrieves users with weak password security.

Get-ADUser -Filter * -Properties Name, PasswordLastSet, badPwdCount

2. Can I identify users with old passwords?

Yes, you can identify users with old passwords by running the script below.

Search-ADAccount -PasswordExpired

3. How can I enforce stronger passwords?

Use fine-grained password policies (FGPP) for stricter password rules.

Set-MsolUser -UserPrincipalName user@domain.com -PasswordNeverExpires $true

Audit the password quality of Active Directory passwords.

ADSelfService Plus trusted by

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