PowerShell Invalid Password Exception

()

In working with Powershell by creating user accounts, may the invalid password exception, InvalidPasswordException error message appears.

New-LocalUser: An exception of type “Microsoft.PowerShell.Commands.InvalidPasswordException”.

PowerShell The error message invalid password exception appers.

Cause

The Local Group Policy for password complexity requirements do not match the input, or the minimum password length is not met. The Powershell error message invalid password exception appers.

Solution

Change Minimum Password Length

Set Minimum Password Length to increase or decrease the password length to the desired length.

powershell error message invalid password exception appers.. Change Minimum Password Length

In Local Group Policy (gpedit.msc), change the Minimum Password Length, 0 for no Minimum Password Length.

Example. creates a user account in the powershell

The following Powershell command creates a user account with a password from the one line command, useful for script processing.

New-LocalUser user1 -Password (ConvertTo-SecureString "8170af" -AsPlainText -Force) -FullName user1 -Description user1 -PasswordNeverExpires -UserMayNotChangePassword

New User Account

If create a local user in Windows 10 or 11 you can use the User Accounts control panel. But you can also use PowerShell to create a new local user. This way we can easily automate creating a local account on Windows devices.

To create a local user with PowerShell you will need to have administrator access to the computer and run PowerShell as admin (elevated). Otherwise, you won’t be able to create accounts.

In this post, I will explain how you can create a new localuser.

New-LocalUser

To create a new local user we are going to use the New-LocalUser cmdlet in PowerShell. The cmdlt provide options to set a password for the account or create an account without a password.

Password exception

As you can see this won’t allow you to run the script autonomous, because you will need to enter a password. This is also the challenge with creating local users, most of the time you want to supply the password in a secure way.

If you run the script remotely or under your own supervision then you could write the password inside a PowerShell script and convert it to a secure string. But keep in mind, anyone who opens the script is able to read the password.

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *