Powershell: create local admin user gives error "specified network password is wrong"


Created a powershell script to create a local admin user but keep on getting
"Exception calling "SetInfo" with "0" argument(s): "The specified network password is not correct."

Please advise what is wrong.

#Create local user and make it administrator
$LocalUser = 'NewLocalAdminUser'
$Computers =   @('servera','serverb')
$Date = "get-date"
$Description = 'Newly created user on $date by $env:username'
$GroupName = 'Administrators'
$Password = 'NewPassword!'
#$Password = Read-Host -AsSecureString
foreach ($computer in $computers)
  if ((Get-LocalGroupMember -Computername $computer -Name $GroupName) -contains $LocalUser) {
    Write-Host "$LocalUser already exists, setting new password" -ForegroundColor Green
    Set-LocalUser -Name $LocalUser -Password $(ConvertTo-SecureString -AsPlainText -Force -String $Password) -Computername $computer
  else {
    Write-host "Setting $LocalUser on $computer"
    New-LocalUser -Name $LocalUser -Computername $computer -Password $(ConvertTo-SecureString -AsPlainText -Force -String $Password) -Description $Description
    Add-LocalGroupMember -Computername $computer -GroupName $GroupName -name $LocalUser
    if ((Get-LocalGroupMember -Computername $computer -Name $GroupName) -contains $LocalUser) {Write-Host "$LocalUser succesfully added to $computer" -ForegroundColor Green}
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
are you using localhost as the name of the server? if so, change it to the actual server name
janhoedtAuthor Commented:
I have no clue what you mean. Why would localhost play any role in my script?
Big MontyWeb Ninja at largeCommented:
you have

$Computers =   @('servera','serverb')

i assume you do not have servers named servera, serverb, etc. If any of those are localhost, you will receive the error you're getting
Joshua GrantomSenior Systems AdministratorCommented:
I'm assuming the PowerShell console you are running this from is running with user credentials that have local admin rights to these machines?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
janhoedtAuthor Commented:
that's correct
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.