none
Add user into localgroup on remote computers RRS feed

  • Question

  • # Add domain user into localgroup of remote computers in list
    $serverList = Get-Content -Path .\serverList.txt
    $serverList | % {
    net localgroup Administrators /add "DOMAIN\user1"
    #

    ^I've been using cmd net localgroup to add user into localgroup on a single computer.

    Is there's a substitute for this so I can run it in PowerShell on a list of remote computers?

    thank you!

    ~Pat


    ---Pat

    Saturday, March 10, 2018 10:38 AM

Answers

  • Here is a filtered list of scripts that can be used for remote management of local groups and accounts:

    https://gallery.technet.microsoft.com/site/search?f%5B0%5D.Type=SearchText&f%5B0%5D.Value=local+group&searchbox_searchImg.x=0&searchbox_searchImg.y=0

    You can also use the PowerShellGet module:

    Find-Module  LocalUserManagement| Install-Module

    You can also use PsRemoting.

    Invoke-Command -Scriptblock {net localgroup Administrators /add "DOMAIN\user1"} -Computer remotepc

    To use any of these you will need to learn basic PwoerShell.  Here is a good place to start.

    Learn PowerShell  


    \_(ツ)_/


    • Edited by jrv Saturday, March 10, 2018 7:37 PM
    • Proposed as answer by BOfH-666 Sunday, March 11, 2018 3:51 AM
    • Marked as answer by Patrick M Sunday, March 11, 2018 4:21 AM
    Saturday, March 10, 2018 7:36 PM
  • Thanks @jrv

    I choose https://gallery.technet.microsoft.com/scriptcenter/Add-AD-UserGroup-to-Local-fe5e9239

    It works on remote computer in a list. I've used it to add users not only to Administrators group, but other group like Remote Desktop Users as well :)


    ---Pat

    • Marked as answer by Patrick M Sunday, March 11, 2018 4:23 AM
    Sunday, March 11, 2018 4:23 AM

All replies

  • Look in the Gallery for many scripts that can do what you ask.  "NET" cannot do this.


    \_(ツ)_/

    Saturday, March 10, 2018 10:43 AM
  • You can use the WinNT provider in PowerShell to deal with local objects, like local groups, remotely. For example, to add a domain user to a local group:

    $LocalGrp = [ADSI]"WinNT://Computer/Administrators,group"
    $DomainUser = [ADSI]"WinNT://domain/username,user"
    If ($LocalGrp.IsMember($DomainUser.Path) -eq $False)
    {
        $LocalGrp.Add($DomainUser.Path)
    }


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Proposed as answer by BOfH-666 Sunday, March 11, 2018 3:51 AM
    Saturday, March 10, 2018 3:18 PM
    Moderator
  • Thanks @Richard Mueller for pointing out the use of WinNT provider.

    I suppose it only works if you run the cmd on a local computer, not remotely?


    ---Pat

    Saturday, March 10, 2018 6:21 PM
  • The code works with any computer.  If you look in the Gallery you will find many more complete scripts that do what you are asking.

    \_(ツ)_/

    Saturday, March 10, 2018 6:25 PM
  • Here is a filtered list of scripts that can be used for remote management of local groups and accounts:

    https://gallery.technet.microsoft.com/site/search?f%5B0%5D.Type=SearchText&f%5B0%5D.Value=local+group&searchbox_searchImg.x=0&searchbox_searchImg.y=0

    You can also use the PowerShellGet module:

    Find-Module  LocalUserManagement| Install-Module

    You can also use PsRemoting.

    Invoke-Command -Scriptblock {net localgroup Administrators /add "DOMAIN\user1"} -Computer remotepc

    To use any of these you will need to learn basic PwoerShell.  Here is a good place to start.

    Learn PowerShell  


    \_(ツ)_/


    • Edited by jrv Saturday, March 10, 2018 7:37 PM
    • Proposed as answer by BOfH-666 Sunday, March 11, 2018 3:51 AM
    • Marked as answer by Patrick M Sunday, March 11, 2018 4:21 AM
    Saturday, March 10, 2018 7:36 PM
  • Thanks @jrv

    I choose https://gallery.technet.microsoft.com/scriptcenter/Add-AD-UserGroup-to-Local-fe5e9239

    It works on remote computer in a list. I've used it to add users not only to Administrators group, but other group like Remote Desktop Users as well :)


    ---Pat

    • Marked as answer by Patrick M Sunday, March 11, 2018 4:23 AM
    Sunday, March 11, 2018 4:23 AM
  • I highly recommend using the Gallery and your search engine to find scripts. Maybe someday you will want to learn PowerShell. If so go here first: Learn PowerShell  

    \_(ツ)_/

    Sunday, March 11, 2018 4:40 AM