I have been following this guide to try and write a powershell script to add a new local user to windows.
I need a username, fullname, description and password, and to check PasswordNeverExpires and UserMayNotChangePassword. I have written the following in an attempt to do so:
$Password = Read-Host -AsSecureString -Prompt 'Create password for new user account:'
New-LocalUser -Name "NewUser" -FullName "New User" -Description "New Execution Account" -Password $Password -PasswordNeverExpires $true -UserMayNotChangePassword $true
However, when running this I get the following error:
New-LocalUser : A positional parameter cannot be found that accepts argument 'True'. At line:2 char:1
+ New-LocalUser -Name "NewUser" -FullName "New User" -Description "New ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-LocalUser], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewLocalUserCommand
If anyone can see where I've gone wrong I would greatly appreciate any help or advice, thank you!