Skip to content
February 27, 2026 • Junior (1-3 years) Script Drop

Secure Active Directory Password Reset PowerShell

By Last updated

Reset an Active Directory password with PowerShell without printing, exporting, or reusing a temporary password across accounts.

Free PDF

Top 10 Intune and Autopilot Enrollment Errors: Causes and Fixes

A free cheat sheet covering ten enrollment errors, each with the symptom, the most likely cause, the fix, and a link to the full guide.

  • Ten real error codes and failures, including 0x80180014, 0x8018002b, 0x801c03f3, 0x800705b4, the ODJConnector logon failure, and the Win32 detection error 0x87d1041c.
  • Every cause and fix checked against Microsoft's own documentation.
  • A link from each entry to the full zakitpro.com article.

You get the free PDF. By subscribing you also agree to receive occasional emails from zakitpro about Intune and Autopilot troubleshooting. Emails are sent through MailerLite. You can unsubscribe anytime with the link in every email. See the privacy page for how your email is handled.

Step-by-step guide

Secure Active Directory Password Reset PowerShell

Password reset scripts should protect the new credential as carefully as the account itself. Never write a temporary password to the console, transcript, log, CSV, ticket, or pipeline output. Use a separate, approved administrator identity and follow your organization’s identity-verification and audit process before changing an account.

Reset one account interactively

This example prompts for a secure string, confirms the target, and asks PowerShell’s ShouldProcess mechanism before changing the password. Review the target and run it first with -WhatIf.

function Reset-DirectoryUserPassword {
    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory)]
        [string]$Identity
    )

    Import-Module ActiveDirectory -ErrorAction Stop
    $account = Get-ADUser -Identity $Identity -Properties Enabled -ErrorAction Stop

    if (-not $account.Enabled) {
        throw "Account '$($account.SamAccountName)' is disabled. Confirm the request before proceeding."
    }

    if ($PSCmdlet.ShouldProcess($account.SamAccountName, 'Reset Active Directory password')) {
        $newPassword = Read-Host "Enter the approved new password for $($account.SamAccountName)" -AsSecureString
        Set-ADAccountPassword -Identity $account.DistinguishedName -NewPassword $newPassword -Reset -ErrorAction Stop
    }
}

Reset-DirectoryUserPassword -Identity 'jdoe' -WhatIf

After reviewing the -WhatIf output and confirming the account, run the command without -WhatIf. Deliver any temporary credential only through the organization’s approved, identity-verified channel. Do not reuse one temporary password for a group of users.

Require a password change at next sign-in

Use this only when policy and the user’s sign-in method support it. It changes the account flag; it does not reset the password.

Set-ADUser -Identity 'jdoe' -ChangePasswordAtLogon $true -WhatIf

Review the target, then repeat without -WhatIf if approved. For bulk operations, take an explicitly reviewed list of account identifiers and preview every target; avoid Get-ADUser -Filter * followed by a domain-wide change.

Review password status

This read-only report identifies accounts with old password timestamps. It does not expose password values, and password age alone is not proof that an account should be reset. Apply your organization’s current identity policy and investigate service accounts and exceptions separately.

Get-ADUser -Filter * -Properties PasswordLastSet, PasswordExpired, PasswordNeverExpires |
    Select-Object Name, SamAccountName, Enabled, PasswordLastSet,
        PasswordExpired, PasswordNeverExpires

To scope a report, use a known OU with -SearchBase and an appropriate filter. Protect the resulting report because account names and security status can be sensitive operational data.

Operational safeguards

  • Confirm the requester’s identity and authorization through the service desk workflow.
  • Use least-privilege delegated rights and a dedicated admin account.
  • Preview targets with -WhatIf; require a second review for bulk changes.
  • Do not place cleartext passwords in script parameters, source control, environment variables, logs, or CSV files.
  • Record the change outcome and ticket reference, but never the password itself.
  • Test the workflow with a nonproduction account before operational use.

See Microsoft’s references for Set-ADAccountPassword and Set-ADUser.

Free PDF

Top 10 Intune and Autopilot Enrollment Errors: Causes and Fixes

A free cheat sheet covering ten enrollment errors, each with the symptom, the most likely cause, the fix, and a link to the full guide.

  • Ten real error codes and failures, including 0x80180014, 0x8018002b, 0x801c03f3, 0x800705b4, the ODJConnector logon failure, and the Win32 detection error 0x87d1041c.
  • Every cause and fix checked against Microsoft's own documentation.
  • A link from each entry to the full zakitpro.com article.

You get the free PDF. By subscribing you also agree to receive occasional emails from zakitpro about Intune and Autopilot troubleshooting. Emails are sent through MailerLite. You can unsubscribe anytime with the link in every email. See the privacy page for how your email is handled.

#PowerShell #Active Directory #password reset #identity security