Modify the password of an Active Directory account.

      Set-ADAccountPassword [-Identity] ADAccount
         [-AuthType {Negotiate | Basic}] [-Credential PSCredential]
            [-NewPassword SecureString] [-OldPassword SecureString]
               [-Partition] [-PassThru] [-Reset]
                  [-Confirm] [-WhatIf] [CommonParameters]

   -AuthType {Negotiate | Basic}
       The authentication method to use: Negotiate (or 0), Basic (or 1)
       A Secure Sockets Layer (SSL) connection is required for Basic authentication.

   -Credential PSCredential
       A user account that has permission to perform this action.
       The default is the current user unless the cmdlet is run from an AD PowerShell provider drive
       in which case the account associated with the drive is the default.

       "User64" or "Domain01\User64" or a PSCredential object.

   -Identity ADAccount
       Specify an AD domain object by providing one of the following values.
       (The identifier in parentheses is the LDAP provider name for the attribute.)

          Distinguished Name 
            Example: DC=Helvetia,DC=corp,DC=SS64,DC=com 
          GUID (objectGUID) 
            Example: 599c4d2e-f72d-4d20-8a78-030d69495f20
          Security Identifier (objectSid) 
            Example: S-1-5-21-5165297888-301467370-576410423-1803
          Security Accounts Manager (SAM) Account Name (sAMAccountName)
            Example: Helvetia

       The cmdlet searches the default naming context or partition to find the object.
       If two or more objects are found, the cmdlet returns a non-terminating error.

       This parameter can also get this object through the pipeline or you can set this
       parameter to an object instance.

   -NewPassword SecureString
       A new password. This value is stored as an encrypted string.

   -OldPassword SecureString
       Supply the most recent password. This value is processed as a encrypted string.

   -Partition string
       The distinguished name of an AD partition.
       The distinguished name must be one of the naming contexts on the current
       directory server. The cmdlet searches this partition to find the object defined by
       the -Identity parameter. 
       The following two examples show how to specify a value for this parameter.
          -Partition "CN=Configuration,DC=Europe,DC=Test,DC=SS64,DC=com"
          -Partition "CN=Schema,CN=Configuration,DC=Europe,DC=Test,DC=SS64,DC=com"
       In many cases, a default value will be used for -Partition if no value is specified.

       Return the new or modified object.
       By default (i.e. if -PassThru is not specified), this cmdlet does not generate any output.

       Specifies to reset the password on an account.
       To use this parameter, you must set the -NewPassword parameter.
       You do not need to specify the -OldPassword parameter.

   -Server string
       The AD Domain Services instance to connect to, this may be a Fully qualified domain name,
       NetBIOS name, Fully qualified directory server name (with or without port number) or AD Snapshot instance.

       Examples:  demo

       Prompt for confirmation before executing the command.

       Describe what would happen if you executed the command, without actually executing the command.

Set-ADAccountPassword sets the password for a user, computer or service account. The -Identity parameter specifies the Active Directory account to modify.

To change a password both the -OldPassword and the -NewPassword parameters must be specified unless -Reset is used.

When -Reset is specified, the -OldPassword parameter is not required and if -NewPassword is left blank, the cmdlet will prompt you for a new password.


Set the password of a user account using the DistinguishedName (prompt for old and new password):

PS C:\> Set-ADAccountPassword -Identity HNicholls

Prompt the user for a new password and then use it to reset the password:

PS C:\> Set-ADAccountPassword -Identity HNicholls -NewPassword (Read-Host -Prompt "Provide New Password" -AsSecureString) -Reset

Set the password of a user account to 'p@ssw0rd' using the DistinguishedName:

PS C:\> Set-ADAccountPassword 'CN=HNicholls,OU=Boston,DC=SS64,DC=com' -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "p@ssw0rd" -Force)

Set the password of a user account to 'p@ssw0rd2' using the SamAccountName:

PS C:\> Set-ADAccountPassword -Identity HNicholls -OldPassword (ConvertTo-SecureString -AsPlainText "0ldPaZZw0rd" -Force) -NewPassword (ConvertTo-SecureString -AsPlainText "p@ssw0rd2" -Force)

“We must plan for freedom, and not only for security, if for no other reason than that only freedom can make security secure” ~ Karl Popper

Related PowerShell Cmdlets

Set-adAccountExpiration - Set the expiration date for an AD account.
Set-LocalUser - Set password for a local user.
Enable-adAccount - Enable an Active Directory account.
Reset-adServiceAccountPassword - Reset the service account password for a computer.
Set-adUser - Modify an AD user (password expiry / password required / ChangePasswordAtLogon).
Q149427 - Change Password using the Settings app.

Copyright © 1999-2023
Some rights reserved