Allen
Allen

Reputation: 181

CMD Command Net User Password expire

Is there a CMD command to set an existing Windows user's property's checkbox, "Password never expires", to be unchecked? (Assumption: The checkbox was previously checked before I unchecked it manually to illustrate the box being unchecked)

enter image description here

I am creating a batch file for windows 10 and I would like to do it programmatically. (I am hardening an OS and baselining it.)

I looked at the CMD command: net user and it does have several password options such as /passwordchg to specify a user can change their own password and /passwordreq which specifies a user must have a password. I find it strange that there isn't one for "Password never expires" (i.e. /passwordexp:{YES|NO}) so my batch file can uncheck that option programmatically. I'm probably missing it in my Google searches but I am unable to find a solution. I include a excerpt of my code:

...
...    
net user %Name% /<somePasswordExpireOption:YES
...
...

Any suggestions are welcome. Thanks in advance.

Upvotes: 1

Views: 7733

Answers (1)

Compo
Compo

Reputation: 38664

Perhaps, as long as they are local not domain:

WMIC UserAccount Where "Name='%Name%'" Set PasswordExpires=TRUE

Upvotes: 4

Related Questions