0

What is going wrong with this:

$pass= "kissa"+"koira"
$pw= ConvertTo-SecureString $pass -AsPlainText -Force

#Create local user
New-LocalUser -Name $username -Password $pw -UserMayNotChangePassword -AccountNeverExpires -PasswordNeverExpires

It creates a user, does not nag about anything. But when I try to login the password is not accepted.

Password should be kissakoira. This is of over simplified example, im trying to create a password with three variables, but even this simple joined string does not work. Its not password complexity as plain kissa or koira work, but not the joined string.

  • 1
    What do you expect the password to be? `Write-Host $Pass` or something like: `'kissa"+"koira'`? Do other passwords work? – iRon Apr 29 '22 at 12:01
  • 3
    You might have password complexity requirements enabled. In such cases it is possible to set a weak password, but one cannot log in with it. – vonPryz Apr 29 '22 at 12:56
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 29 '22 at 17:35
  • Password should be kissakoira. This is of over simplified example, im trying to create a password with three variables, but even this simple joined string does not work. Its not password complexity as plain kissa or koira work, but not the joined string. – Marko Mård Apr 30 '22 at 14:19

1 Answers1

0

This seems to work:

$pw="kissa"+"koira"| ConvertTo-SecureString -AsPlainText -Force

#Create local user New-LocalUser -Name $username -Password $pw -UserMayNotChangePassword -AccountNeverExpires -PasswordNeverExpires

  • what is the meaningful difference between your Answer code and the Question code? what is different & why? – Lee_Dailey May 01 '22 at 19:39
  • That is what I am wondering myself. Only difference is that the answer works and original does not. Does the ConvertTo-SecureString not like variables or something.. – Marko Mård May 03 '22 at 04:59
  • generally, an Answer otta more about `why` than just a blob of code with no rationale. ///// also, you likely otta add code formatting around the code to make it easy to read. [*grin*] – Lee_Dailey May 03 '22 at 06:09