- List of user groups command line
- Add user to group from command line (CMD)
- Add user to a group
- Few more examples:
- NET ACCOUNTS / NET USER / NET GROUP
- Описание команды NET LOCALGROUP
- Синтакис команды NET LOCALGROUP
- Примеры команды NET LOCALGROUP
- Видео — Работа с утилитой NET LOCALGROUP
- CMD. Управление пользователями в Windows.
- Команда NET USER
- Синтаксис команды NET USER
List of user groups command line
On Windows OS we can find the list of local user groups created on a system from Contorl Panel -> User Accounts. This information can be obtained from command line also using net command. Syntax is shown below.
Example: Running this command shows the following local groups on my system.
How to list the users in a local group?
Use the below command to know the list of members of a group from command line.
For example to get the list of all remote desktop users on a system we can run the below command.
How to find the list of all groups a user is member of?
You can run the below command to list the groups a user is member of. This command prints the details of the given user account. You can find the group membership information in the last two line of this command output.
Useful references, however “net use username” should be changed to “net user username”
Thank you Kennedy. Corrected the command.
Please get me a command which will display all local users as: LOGIN, FULL NAME, DESCRIPTION, GROUP etc..
I’d just like to express my frustration with this API. As you can see in these examples, thet net API localgroups functionality will happily list all members of a group. However the net user code completely ignores system accounts, as does most of the rest of what Windows makes available. Internally they are organized as a subclass of Win32_Account but not Win32_UserAccount. So it’s possible to retrieve a bunch of useless information from the Windows API. This happens with LookupAccountSid as well. If you give it an SID like S-1-5-20, it will give you an answer. But the answer it gives you can’t be used as input for anything else, which is obnoxious.
You can query if users exist by doing
SET /P query_user=What user do i look for?
::Take out /domain if you want to look on the local computer
Net User %query_user% /domain
if NOT %errorlevel% == 0 goto s_error_1
if %errorlevel% == 0 goto s_success_1
“net user /domain username” lists only the groups to which the username is a direct member. It can’t show nested groups. I was doing a quick check to see if a username was a member of a group:
net user /domain username | find “Group Name”
That fails since the user is not directly a member of “Group Name”. In reality, they are a member, as they’re a member of a nested group.
Any idea of a command line that will expand groups to look for a particular member? I’ve used the “dsquery” and “dsget” commands, but they are only present if the AD tools are installed.
Very useful thanks, didn’t worked for me the first time.
The command is not case sensitive.
For example “NET USER /DOMAIN MYDOMAIN/MyUser” Didn’t worked.
But “NET USER /DOMAIN MyUser” works fine!
So not necessary to put explicitly the domain.
By the way it means also you can’t query another domain than the main one you are logged on to ?
Is there any option where we can get the multiple user’s output in excel for local computer and remote computer
net user userName
Add user to group from command line (CMD)
Windows provides command line utilities to manager user groups. In this post, learn how to use the command net localgroup to add user to a group from command prompt’
Add user to a group
Run the steps below –
- Open elevated command prompt
- Run the below command
For example to add a user ‘John’ to administrators group, we can run the below command.
Few more examples:
To add a domain user to local users group:
This command should be run when the computer is connected to the network. Otherwise you will get the below error.
To add a domain user to local administrator group:
To add a user to remote desktop users group:
To add a user to debugger users group:
To add a user to Power users group:
This command works on all editions of Windows OS i.e Windows 2000, Windows XP, Windows Server 2003, Windows Vista and Windows 7. In Vista and Windows 7, even if you run the above command from administrator login you may still get access denied error like below.
The solution for this is to run the command from elevated administrator account. See How to open elevated administrator command prompt
When you run the ‘net localgroup’ command from elevated command prompt:
To list the users belonging to a particular group we can run the below command.
For example to list all the users belonging to administrators group we need to run the below command.
NET ACCOUNTS / NET USER / NET GROUP
The NET command is used to manage user accounts and groups.
View the current password & logon restrictions for the computer (plus machine role: Server/ Workstation).
NET ACCOUNTS
View the current password & logon restrictions for the domain.
NET ACCOUNTS /DOMAIN
Set the number of minutes a user has before being forced to log off when the account expires or valid logon hours expire
NET ACCOUNTS /FORCELOGOFF:minutes /DOMAIN
Prevent forced logoff when user accounts expire
NET ACCOUNTS /FORCELOGOFF:NO /DOMAIN
Set the minimum number of characters for a password.
NET ACCOUNTS /MINPWLEN:C /DOMAIN
The range is 0-14 characters; the default is 6 characters.
Set the maximum number of days that a password is valid.
NET ACCOUNTS /MAXPWAGE:dd /DOMAIN
The range is 1-49710; the default is 90 days.
Set passwords to never expire.
NET ACCOUNTS /MAXPWAGE:UNLIMITED /DOMAIN
Set a minimum number of days that must pass before a user can change a password (default = 0)
NET ACCOUNTS /MINPWAGE:dd /DOMAIN
Require that new passwords be different from ‘x’ number of previous passwords
NET ACCOUNTS /UNIQUEPW:x /DOMAIN
The range for ‘x’ is 1-24
View the password properties of user account ‘Ella’, this will show if the account requires a password:
NET USER Ella | findstr «Password»
Change the properties of user account ‘Ella’ to make the password not required. To reverse this, change ‘false’ to ‘true’.
WMIC useraccount where name=’Ella’ set PasswordRequired=false
Synchoronise the user accounts database (PDC and BDC)
NET ACCOUNTS /SYNC /DOMAIN
View user account details
NET USER [/DOMAIN]
Add a user account.
NET USER username
Modify a user account.
NET USER [username [password | *] [options]] [/DOMAIN]
Delete a username
NET USER username [/DELETE] [/DOMAIN]
Generate a random password:
NET USER administrator /random
Add a group
NET GROUP groupname /ADD [/COMMENT:»text»] [/DOMAIN]
NET LOCALGROUP groupname /ADD [/COMMENT:»text»] [/DOMAIN]
Edit a group
NET GROUP [groupname [/COMMENT:»text»]] [/DOMAIN]
NET LOCALGROUP [groupname [/COMMENT:»text»]] [/DOMAIN]
Delete a group
NET GROUP groupname /DELETE [/DOMAIN]
NET LOCALGROUP groupname /DELETE [/DOMAIN]
Add a user to a group
NET GROUP groupname username [. ] /ADD [/DOMAIN]
NET LOCALGROUP groupname username [. ] /ADD [/DOMAIN]
Delete a user from a group
NET GROUP groupname username [. ] /DELETE [/DOMAIN]
NET LOCALGROUP groupname username [. ] /DELETE [/DOMAIN]
LOCALGROUP will create/modify a group that is local to the computer rather than an Active Directory domain-wide group.
Описание команды NET LOCALGROUP
Команда NET LOCALGROUP преназначена для добавления, отображения и изменения локальных групп компьютера в операционной системе Windows. Ввод команды NET LOCALGROUP без параметров выводит имя сервера и имена локальных групп компьютера.
Для управления учетными записями пользователей используется команда NET USER , а для управления учетныеми данными пользователей NET ACCOUNTS.
Синтакис команды NET LOCALGROUP
net localgroup [имя_группы [/comment:»текст»]] [/domain]
net localgroup [имя_группы [/domain]]
net localgroup [имя_группы имя [ . ] [/domain]], где
- имя_группы — Имя локальной группы для добавления, удаления или раскрытия. При запуске команды net localgroup имя_группы без дополнительных параметров выводится список пользователей или глобальных групп, входящих в локальную группу.
- /comment:»текст» — Добавление комментария для новой или существующей группы. Длина комментария может составлять до 48 знаков. Текст следует заключать в кавычки.
- /domain — Выполнении операции на основном контроллере текущего домена. В противном случае операция осуществляется на локальном компьютере.
- имя [ . ] — Список из одного или нескольких имен пользователей или групп для добавления или удаления из локальной группы.
- /add — Добавление глобальной группы или пользователя в локальную группу. Для пользователей или глобальных групп группы, добавляемых в локальную группу, должны иметься учетные записи.
- /delete — Удаление группы или пользователя из локальной группы.
- net help localgroup —Отображение справки для указанной команды net.
Примеры команды NET LOCALGROUP
- Чтобы вывести список всех локальных групп на локальном сервере, введите: net localgroup;
- Чтобы добавить локальную группу «Group1» в локальную базу учетных записей пользователей, введите: net localgroup Group1 /add;
- Чтобы добавить локальную группу «Group1» в базу учетных записей пользователей домена, введите: net localgroup Group1 /add /domain;
- Чтобы добавить учетные записи существующих пользователей «User1», «User2» и «User3» в группу «Group1» домена, введите: net localgroup Group1 User1 User2 Use3 /add /domain;
- Чтобы вывести список пользователей локальной группы «Group1», введите: net localgroup Group1;
- Чтобы добавить комментарий к локальной группе «Group1», введите: net localgroup Group1 /comment:»Руководящий персонал».
Видео — Работа с утилитой NET LOCALGROUP
CMD. Управление пользователями в Windows.
Управление пользователями в Windows, помимо графической оснастки «Учетные данные пользователей», расположенной в панели управления, можно производить с помощью командной строки.
Команда NET USER
Команда NET USER предназначена для просмотра, добавления или редактирования учетных записей пользователей на компьютерах. При выполнении команды в командной строке без параметров отображается список учетных записей пользователей Windows, присутствующих на компьютере(локальные УЗ). Информация об учетных записях пользователей хранится в базе данных Windows.
Синтаксис команды NET USER
net user [имя_пользователя [пароль | *] [параметры]] [/domain]
net user имя_пользователя <пароль | *>/add [параметры] [/domain]
net user имя_пользователя [/delete] [/domain], где
- имя_пользователя — Указывает имя учётной записи пользователя, которую можно добавить, удалить, отредактировать или просмотреть. Имя может иметь длину до 20 символов.
- пароль — Присваивает или изменяет пароль пользователя. Введите звездочку (*) для вывода приглашения на ввод пароля. При вводе с клавиатуры символы пароля не выводятся на экран.
- /domain — Выполняет операцию на контроллере основного для данного компьютера домена.
- параметры — Задает параметр командной строки для команды.
- net help команда — Отображение справки для указанной команды net.
- /delete — Удаление учетной записи пользователя.