Modify the password of an Active Directory account.
Syntax
Set-ADAccountPassword [-Identity] ADAccount
[-AuthType {Negotiate | Basic}] [-Credential PSCredential]
[-NewPassword SecureString] [-OldPassword SecureString]
[-Partition] [-PassThru] [-Reset]
[-Confirm] [-WhatIf] [CommonParameters]
Key
-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 display 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.
-PassThru
Return the new or modified object.
By default (i.e. if -PassThru is not specified), this cmdlet does not generate any output.
-Reset
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.SS64.com demo demoDC02.demo.ss64.com demoDC02.demo.ss64.com:3268
-Confirm
Prompt for confirmation before executing the command.
-WhatIf
Describe what would happen if you executed the command, without actually executing the command.
CommonParameters:
-Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
-OutBuffer -OutVariable.
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.
Examples
Set the password of a user account using the DistinguishedName (prompt for old and new password):
PS C:\> Set-ADAccountPassword -Identity JMarbles
Prompt the user for a new password, store the password in a temporary variable ($newPassword), and then use it to reset the password:
PS C:\> $newPassword = (Read-Host -Prompt "Provide New Password" -AsSecureString)
PS C:\> Set-ADAccountPassword -Identity JMarbles -NewPassword $newPassword -Reset
Set the password of a user account to 'p@ssw0rd' using the DistinguishedName:
PS C:\> Set-ADAccountPassword 'CN=JMarbles,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 JMarbles -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.
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).