PowerShell Can Throw a SetInfo With 0 Argument(s) Error When Creating a User

Problem scenario
You run a PowerShell script that has a command setinfo.  For example, the script is like this:

        #...
        $userName = 'jdoe'
        $compName = $env:COMPUTERNAME
        $cona = [ADSI]"WinNT://$compName"
        $user = $cona.Create('User',$userName)
        $user.SetInfo()

You get "Exception calling "SetInfo" with "0" argument(s): "The password does not meet the password policy requirements. Check the minimum password length, password complexity and password history requirements."

You may go to Administrative Tools -> Local System Security and find the Account password requirements are met.  How do you get around this problem?

Solution
Instead of using $user.SetInfo, try this set of commands:

$userName = 'jdoe'
$secretp = 'sp3shulP@ssw0rd'
net user $userName /add $secretp

Leave a comment

Your email address will not be published.