Category filter
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 to group users on multiple devices simultaneously.
Batch Script
|
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
|
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”
