1

I'm using the following command in a PowerShell script to create new local user accounts. The account is created successfully, the correct password is set and I can logon to it fine.

NET USER USER_01 "Password" /ADD /expires:NEVER /fullname:"USER_01" /comment:"MY Comment"

But after about 1 to 2 weeks the account suddenly expires and I'm no longer able to RDP to the account.

Error

I have tried both the parameters /expires:NEVER and /expires:0 but both still expire down the line.

Am I missing something here?

Richard
  • 133

1 Answers1

1

Your usage of NET USER with /EXPIRES:NEVER appears to be correct.
https://support.microsoft.com/en-us/kb/251394
However it is a VERY old tool, probably not getting much attention back in Redmond. After I create an account that way, and look at the account, the PNE flag is not set.

Why are you still using "NET.EXE"? There are powershell cmdlets for new user creation that are much more useful.

write-host "Password for new account:"
$pass1 = read-host -assecurestring
$pass2 = ConvertTo-SecureString -AsPlainText "something" -force
New-ADUser -SamAccountName "glenjohn" -Name "glenjohn" -GivenName "Glen" -Surname "John" -DisplayName "Glen John" -UserPrincipalName "glenjohn@stuff.com" -Accountpassword $pass1 -enabled $true -PasswordNeverExpires $true

EDIT:

Oops! I overlooked the word "local" in your post.
You CAN do local account in powershell, but it takes 8-10 lines of code.
Try this:

NET USER JOE "password" /ADD /y
WMIC USERACCOUNT WHERE "Name='JOE'" SET PasswordExpires=FALSE
Clayton
  • 4,653