ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Managing Windows Local Groups with Net LocalGroup

    IT Discussion
    sam windows administration system administration scottalanmiller windows cmd net local groups user management
    2
    6
    1.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by scottalanmiller

      Before PowerShell, net localgroup was the standard mechanism for managing local users on Windows and still remains a simple, effective tool for doing so from the command line. If you ever need to work on extremely old machines without PowerShell, it is also the only way to do so. It is part of the net family of command line Windows utilities.

      It is very important to remember that net user is for managing the local users on the machine where you are running the command. It is not for managing things like Active Directory users.

      Using net user is simple, fast, and straightforward. We will learn best for straightforward examples.

      List Local Groups

      net localgroup
      

      Get Details of Specific Local Group

      net localgroup administrators
      

      Add Local User to a Local Group

      net localgroup administrators sally /add
      

      Add an Active Directory Domain User to a Local Group

      net localgroup administrators mydomain\sally /add 
      

      Create a New Local Group

      net localgroup mynewgroup /add
      

      Delete a Local Group

      net localgroup mynewgroup /delete
      

      The net localgroup command makes local group management exceptionally quick and easy, no matter how you are accessing a system and is a great example of where command line management is often much simpler and faster than a GUI.


      Part of a series on Windows Systems Administration by Scott Alan Miller

      ObsolesceO 1 Reply Last reply Reply Quote 4
      • ObsolesceO
        Obsolesce @scottalanmiller
        last edited by

        @scottalanmiller said in Managing Windows Local Groups with Net LocalGroup:

        If you ever need to work on extremely old machines without PowerShell, it is also the only way to do so.

        I truly hope it's almost nobody still having to deal with user management and AD from Windows XP and earlier desktops.

        But if you love using net commands, they work well in PowerShell scripts.

        scottalanmillerS 1 Reply Last reply Reply Quote 0
        • scottalanmillerS
          scottalanmiller @Obsolesce
          last edited by scottalanmiller

          @Obsolesce said in Managing Windows Local Groups with Net LocalGroup:

          @scottalanmiller said in Managing Windows Local Groups with Net LocalGroup:

          If you ever need to work on extremely old machines without PowerShell, it is also the only way to do so.

          I truly hope it's almost nobody still having to deal with user management and AD from Windows XP and earlier desktops.

          It's a lot later before PowerShell tools for this existed, that's actually decently recent. It was only a "few" releases of PowerShell ago where these tools did not exist.

          I just tested a fully up to date Windows 7 system and the PS tools do not exist there yet. You can add them, but they are not part of the standard PS tool sets on Windows Vista and 7, and possibly later, that's just what I have on hand to test. If you are in the support space and supporting ad hoc companies, or work in the MSP space, or work with one of customers, it's actually the norm to have PowerShell lack the expecting tooling for many tasks still today. Even on well maintained, fully updated systems.

          ObsolesceO 1 Reply Last reply Reply Quote 1
          • ObsolesceO
            Obsolesce @scottalanmiller
            last edited by

            @scottalanmiller said in Managing Windows Local Groups with Net LocalGroup:

            @Obsolesce said in Managing Windows Local Groups with Net LocalGroup:

            @scottalanmiller said in Managing Windows Local Groups with Net LocalGroup:

            If you ever need to work on extremely old machines without PowerShell, it is also the only way to do so.

            I truly hope it's almost nobody still having to deal with user management and AD from Windows XP and earlier desktops.

            It's a lot later before PowerShell tools for this existed, that's actually decently recent. It was only a "few" releases of PowerShell ago where these tools did not exist.

            I just tested a fully up to date Windows 7 system and the PS tools do not exist there yet. You can add them, but they are not part of the standard PS tool sets on Windows Vista and 7, and possibly later, that's just what I have on hand to test. If you are in the support space and supporting ad hoc companies, or work in the MSP space, or work with one of customers, it's actually the norm to have PowerShell lack the expecting tooling for many tasks still today. Even on well maintained, fully updated systems.

            net user doesn't work in that version of PowerShell? Could have sworn i used it in PowerShell way back...

            scottalanmillerS 1 Reply Last reply Reply Quote 0
            • scottalanmillerS
              scottalanmiller @Obsolesce
              last edited by

              @Obsolesce said in Managing Windows Local Groups with Net LocalGroup:

              net user doesn't work in that version of PowerShell? Could have sworn i used it in PowerShell way back...

              net user works in everything, PS, CMD, anything, because it's not part of any of them. It's a separate command line that goes way, way back. It's the alternatives to net user that don't exist until much later.

              1 Reply Last reply Reply Quote 0
              • ObsolesceO
                Obsolesce
                last edited by Obsolesce

                I ran into a language issue the other day when writing a PowerShell script that uses net localgroup and thought it could be useful to others:

                Depending on the language your Windows device is set to, the local Administrators group will be different, so the typical net localgroup administrators domain\user /add command will fail.

                Implementing the following will grab the actual name of the group by it's SID first, then use that result.
                Note that this is written to work in PowerShell, not CMD.exe.

                # Gets the name of the local Administrators group in appropriate language
                    $localAdminGroupName = (Get-WmiObject win32_group -filter "LocalAccount = $TRUE And SID = 'S-1-5-32-544'" | Select-Object -Expand name)
                    Write-Output "Local Administrators group detected as: [$localAdminGroupName]"
                # Sets the users as a local admin using appropriate local Administrators group name
                    net localgroup $localAdminGroupName domain\user /add
                # Gets local Administrators group members
                    net localgroup $localAdminGroupName
                
                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post