# Scripts to add users to a group on Windows devices

User Management on Windows devices becomes easier when the users are grouped. Hexnode lets admins [deploy scripts](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) to group users on multiple devices simultaneously.

 Note: 
**Supported Versions**:

The scripts given below will be supported on the following versions:

- Windows 10 v1607+ (Pro, Enterprise, Education)
- Windows 11 (Pro, Enterprise, Education)

[ ](https://developer.android.com/develop/connectivity/uwb#uwb-enabled_mobile_devices)

 

 Disclaimer:The sample scripts provided below are adapted from third-party open-source sites.

 

Batch Script
------------

Batch script to add users to a group on Windows

net localgroup group\_name UserLoginName /add 

   1

  net localgroup group\_name UserLoginName /add 

   

 

  

E.g., To add the user **Josh** to the group of **Users**,

*net localgroup Users Josh /add*

PowerShell Script
-----------------

PowerShell script to add users to a group on Windows

$group = "group name" $user = "user name" if (Get-LocalGroup -Name $group -ErrorAction SilentlyContinue) { if (Get-LocalUser -Name $user -ErrorAction SilentlyContinue) { Add-LocalGroupMember -Group $group -Member $user Write-Output "User '$user' added to group '$group'." } else { Write-Output "User '$user' does not exist." } } else { Write-Output "Group '$group' does not exist." } 

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

  $group = "group name"

$user = "user name"

if (Get-LocalGroup -Name $group -ErrorAction SilentlyContinue) {

 if (Get-LocalUser -Name $user -ErrorAction SilentlyContinue) {

 Add-LocalGroupMember -Group $group -Member $user 

 Write-Output "User '$user' added to group '$group'."

 } else {

 Write-Output "User '$user' does not exist."

 }

} else {

 Write-Output "Group '$group' does not exist."

} 

   

 

  

*$group = “group name”*

*$user = “user name”*

In the above script, replace the terms “group name” and “user name” with the actual names. For example, to add the user Josh to the group Users the script should be:

*$group = “Users”*

*$user = “Josh”*

[![Script output message displayed in the Action History tab in Hexnode UEM portal](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2021/09/Add-user-to-group-%E2%80%93-Hexnode-UEM-portal-output-300x149.png)](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2021/09/Add-user-to-group-%E2%80%93-Hexnode-UEM-portal-output-300x149.png "Add user to group – Hexnode UEM portal output")

 Notes:- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.