user128300
user128300

Reputation:

How to set password expiration date of Active Directory user

I am writing an application that communicates with Active Directory and I need to test how it behaves when the password of a user account in Active Directory has only a few days until its expiration date.

Therefore my question is: how can I set the password expiration date of a particular Active Directory user account to a date like "today + 2 days" (without changing the password expiration policy, of course!). I am looking either for manual way to do that or a programmatic solution (e.g. VBScript or C# based).

I have already tried these two approaches:

Code example:

strUserName = "test97"
Set objUser = GetObject("LDAP://CN=" & strUserName & ",CN=Users,DC=mydomain,DC=com")
dtmDate = Now+2
objUser.PasswordExpirationDate = dtmDate 
objUser.SetInfo
MsgBox "Successfully changed password expiration date"

Upvotes: 1

Views: 6818

Answers (2)

sternr
sternr

Reputation: 6506

The PasswordExpirationDate property is readonly.

I might be wrong but I think your options are either to set the password to expired (by using the pwdLastSet), or by changing\shortening the maxPwdAge property.

Upvotes: 0

Brian Desmond
Brian Desmond

Reputation: 4503

This is not possible. You can only mark the password as expired.

Upvotes: 1

Related Questions