# Create local user accounts by PS on remote computers

**URL:** <https://forums.powershell.org/t/create-local-user-accounts-by-ps-on-remote-computers/23724>\
**Category:** PowerShell Help\
**Created:** [March 6, 2024, 2:08am UTC](https://forums.powershell.org/t/create-local-user-accounts-by-ps-on-remote-computers/23724 "2024-03-06T02:08:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fromusofa](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/fromusofa/32/5230_2.png) [@fromusofa](https://forums.powershell.org/u/fromusofa)\
**Post date:** [March 6, 2024, 2:08am UTC](https://forums.powershell.org/t/create-local-user-accounts-by-ps-on-remote-computers/23724/1 "2024-03-06T02:08:44Z")

</div>

-1

I am trying to create a simple script that prompts a local admin user to create a local user account on 6 remote computers in a Windows Workgroup. The script should prompt for the name of the user, password, and the group to which it will be a member of, and repeats the execution of the commands in all 6 computers while the script initiated only once. All 6 computers have the admin account with the same username/password.

I know the PS commands that can be used are - New-LocalUser, Add-LocalGroupMember and PSSession, but I just can’t make it automated enough to run with the minimal input by a local admin.

I tried the following script and saved it on PC01 to run from Powershell. However it gives an error that account already exists whenever it tries to create the account on PC02 and PC03 after it successfully creates the account on PC01. Also it does not Read host when remoting in to PCs.

Enter-PSSession -ComputerName PC01 New-localUser Add-LocalGroupMember -Group Users Exit-PSSession Enter-PSSession -ComputerName PC02 New-localUser Add-LocalGroupMember -Group Users Exit-PSSession Enter-PSSession -ComputerName PC03 New-localUser Add-LocalGroupMember -Group Users Exit-PSSession

Thanks.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 6, 2024, 7:02am UTC](https://forums.powershell.org/t/create-local-user-accounts-by-ps-on-remote-computers/23724/2 "2024-03-06T07:02:09Z")

</div>

That’s basically the same question again

> [@Local user accounts creation on remote computers in a workgroup](https://forums.powershell.org/t/local-user-accounts-creation-on-remote-computers-in-a-workgroup/23722):
>
> 0 I am trying to create a simple script that prompts a local admin user to create a local user account on 6 remote computers in a Windows Workgroup. The script should prompt for the name of the user, password, and the group to which it will be a member of, and repeats the execution of the commands in all 6 computers while the script initiated only once. All 6 computers have the admin account with the same username/password. I know the PS commands that can be used are - New-LocalUser, Add-Local…

Why don’t you update your already existing thread?

and again:

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you potentially wasting their time.

Thanks

> <https://stackoverflow.com/questions/78111481/how-to-create-local-user-accounts-by-powershell-on-remote-computers>

And again:

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( \</\> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

[How to format code in PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif) 1 \<---- Click 👆🏽 😉

( !! Sometimes the _preformatted text_ button hides behind the settings gear symbol. 😉 )

Since you did not format your code and your code looks like it is one big line it’s hard to say where exactly your issue is. There should be line breaks at least.

The cmdlet

> **[Enter-PSSession (Microsoft.PowerShell.Core) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/enter-pssession?view=powershell-7.4)**
>
> The Enter-PSSession cmdlet starts an interactive session with a single remote computer. During the session, the commands that you type run on the remote computer, just as if you were typing directly on the remote computer. You can have only one...

is made for interactive use. If you want to remote into another computer from a script you should use

> **[Invoke-Command (Microsoft.PowerShell.Core) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-7.4)**
>
> The Invoke-Command cmdlet runs commands on a local or remote computer and returns all output from the commands, including errors. Using a single Invoke-Command command, you can run commands on multiple computers. To run a single command on a remote...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [April 5, 2024, 7:02am UTC](https://forums.powershell.org/t/create-local-user-accounts-by-ps-on-remote-computers/23724/3 "2024-04-05T07:02:35Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
