Computer Management bat files - Part 2: Groups



In today's article we are going over how to manage groups with a set of simple batch files. If you haven't read it you may want to start at article one Computer management bat files - Part 1: Users.

Group Management Scripts

The first part of our scripting is to create scripts for managing user accounts. We will create individual scripts for viewing, adding, enabling, disabling, user accounts as well as changing their passwords.

How to list groups

To list groups is a simple command
Net Localgroup
This will list all the groups on your computer as shown in the picture below.

List users in a Group

So know that we know how to list the groups, lets create a script that lists the users in those groups.

     @echo off
     :ListGroups
          Net localgroup
          setlocal EnableDelayedExpansion
          echo  Type Below Requirements:
          echo.
          :group
               set /p grp= Type Group:
               if [!grp!]==[] goto group   
          net localgroup %grp%
          pause
     goto ListGroups

The ran script should look like below.

Add a user to a Group

So know that we know how to list the groups and which users are in them, lets create a script that adds users to those groups.

     @Echo off
     :AddGroup
          Net LocalGroup
          setlocal EnableDelayedExpansion
          echo  Type Below Requirements:
          echo.
          :username
               set /p usr= Type Username:
               if [!usr!]==[] goto username
          :group
               set /p grp= Type Group:
               if [!grp!]==[] goto group   
          net localgroup %grp% %usr% /add
          pause
     goto AddGroup

The ran script should look like below.

Remove a user from a Group

So know that we know how to list the groups and which users are in them as well as add users to groups, lets create a script that removes users to those groups.

     @Echo off
     :RemGroup
          Net LocalGroup
          setlocal EnableDelayedExpansion
          echo  Type Below Requirements:
          echo.
          :username
               set /p usr= Type Username:
               if [!usr!]==[] goto username
          :group
               set /p grp= Type Group:
               if [!grp!]==[] goto group   
          net localgroup %grp% %usr% /delete
          pause
     goto RemGroup

The ran script should look like below.

As I ran these scripts I initially had written "net localgroups" instead of "net localgroup," that is why the list isn't there in my screen shots. Next time we will go into building a menu to merge all the little scripts into.


Comments

Popular posts from this blog

Star Trek: Akira-class Bridge (TNG-era)

Hapes Consortium Uniforms