cancel
Showing results for 
Search instead for 
Did you mean: 
cwall333
New Member

using Powershell to create a new local Windows user

Hello:

 

We have written a script to add a new local admin user to our systems we have in our LogMeIn portal

and it works to create the user, but once created the new user is still not able to be used to connect with LMI.

 

Not until we remote in with the old user and log out - then back in with the new user.

When we do that Windows sets up the new user and after that we can use LMI to access that system.

 

Has anyone found a way to avoid that step and to use LMI and a powershell

script to both create the user and also set that user up in Windows so that we can

avoid the manual step of having to first log in once as the new user

so that it then works in LMI ?


script:

 

$password1 = ConvertTo-SecureString “password1” -AsPlainText -Force
$password2 = ConvertTo-SecureString “password2” -AsPlainText -Force

if (Get-LocalUser -Name "user1")
{
Enable-LocalUser -Name "user1"
Set-LocalUser -Name "user1" -Description "User 1" -Password $password1
} else
{
New-LocalUser -Name "user1" -Description "User 1" -Password $password1
Add-LocalGroupMember -Group "Administrators" -Member "user1"
}

# New-LocalUser -Name "user2" -Description "User 2" -Password $password2
# Add-LocalGroupMember -Group "Administrators" -Member "user2"

1 REPLY 1
devtt
New Member

Re: using Powershell to create a new local Windows user

Hi cwall333,

 

Not sure if you found the solution but I think your issue is the order of operations? You'll need to run the Enable-LocalUser cmdlet after the user account is created.

 

I ran a test on my end and seems to work. Let me know if any questions.