troubleshooting Question

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

Avatar of janhoedt
janhoedt asked on
5 Comments1 Solution506 ViewsLast Modified:

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}
Joshua Grantom
Systems Administrator
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros