?
Solved

Script to automate additon/removal of users

Posted on 2003-03-25
15
Medium Priority
?
261 Views
Last Modified: 2013-12-19
I have an NT 4.0 domain environment.  I need a script that adds/removes users from various NT domain groups.
0
Comment
Question by:asafayan
  • 6
  • 3
  • 2
  • +2
13 Comments
 
LVL 1

Expert Comment

by:CPscripter
ID: 8205046
You can use the Usrtogrp.exe program included in the resource kit. To use it you need to create a source text file in this syntax:

domain: domainname
localgroup(or globalgroup): groupname
User1
User2
User3
(etc...)

Then run usrtogrp passing the name of the file created above as the only parameter

If you want to do this from a single command line, you can use the following batch file.

AddToLocal.bat
----
@echo=off
echo domain: %1 >usrtogrp.dat
echo localgroup: %2 >>usrtogrp.dat
:loop
if "%3"=="" goto :exitloop
echo %3 >>usrtogrp.dat
shift
goto :loop
:exitloop
usrtogrp usrtogrp.dat
del usrtogrp.dat >nul
----
Edit the localgroup line if you want to add to a global group.
Call this batch file as follows
AddToLocal domain-name group-name user1 [user2]...
If you have spaces imbedded in the group name, enclose that parameter in double quotes.

Hope this helps

Claude
0
 
LVL 86

Accepted Solution

by:
oBdA earned 672 total points
ID: 8206099
You're looking for

net group "<group name>" username /add
net group "<group name>" username /delete
net localgroup "<group name>" username /add
net localgroup "<group name>" username /delete
or maybe cusrmgr.exe from the W2k's Resource Kit.

As for the adding/removing itself, you need to be a bit more specific. Do you want a few users to be added/removed from many groups, do you want many users to be added/removed from few groups, do you have the users and or groups in a text file?
0
 

Author Comment

by:asafayan
ID: 8206151
Hi CPScriptor,

Can the Usrtogrp.exe program be used to delete users from NT groups?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:asafayan
ID: 8206278
Hi oBdA,

I have many users to delete from a single NT group.  Yes, the users are in a text file.
0
 
LVL 2

Expert Comment

by:bonzai
ID: 8210270
Hi

to delete many users from a single group, you could use this "single-line-Batchfile":

------------
FOR /F "tokens=1* delims=" %%j in (usernames.txt) do (echo net group yourgroup %%j /delete /DOMAIN)
-----------

!!!! this will not work until you remove the "echo" command!!!!

handle with care!


The Users should be stored in the Usernames.txt File.
------------
User1
User2
User3
------------

be careful joking around with Users and Scripts, they are easy to delete but hard to restore :-)

greets
bonzai

0
 
LVL 2

Expert Comment

by:bonzai
ID: 8210289
PS: i just tried this with a local group (syntax "net localgroup" without the /DOMAIN)

Not really sure if the /DOMAIN is needed if the script runs on a Domaincontroller

b
0
 

Author Comment

by:asafayan
ID: 8210543
Bonza,

I am not following your syntax...is this be how it should:

FOR /F "tokens=1* delims=" %%j in c:\usernames.txt do echo net group testgroup %%j /delete /testdomain

You have () in two locations...I assume that I remove them? Can I run this from a workstation with admin priviledges?
0
 
LVL 1

Assisted Solution

by:CPscripter
CPscripter earned 664 total points
ID: 8211561
Unfortunately the usrtogrp program won't delete. Deleting multiple members from a group isn't difficult in user manager and the other options selected here are good for scripting a delete. Addusers will be easy to use if you already have a text file, but only for additions.
0
 
LVL 2

Expert Comment

by:bonzai
ID: 8212174
My syntax should be ok, assuming the usernames.txt is in the same directory like your batchfile. keep the ()'s

it "should" work an a workstation with the /DOMAIN parameter.

greets
bonzai
0
 
LVL 2

Assisted Solution

by:bonzai
bonzai earned 664 total points
ID: 8212229
read before post, bonzai!!!

/DOMAIN will be /DOMAIN, it's not a variable for your domainname... just /DOMAIN

Syntax is:
FOR /F "tokens=1* delims=" %%j in (usernames.txt) do (echo net group yourgroup %%j /delete /DOMAIN)

just replace the usernames.txt with the filename where your Usernames are stored. The "echo" will just display what will be done. Remove it, when you think that everything will work fine.

(sorry my bad english)

bonzai
0
 

Expert Comment

by:CleanupPing
ID: 9158225
asafayan:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 2

Expert Comment

by:bonzai
ID: 9178745
cleanupPing

my coling recommendation:

split points between CPscripter oBdA and bonzai

b.
0
 
LVL 2

Expert Comment

by:bonzai
ID: 9178747
coling = closing ;-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Trying to figure out group policy inheritance and which settings apply where can be a chore.  Here's a very simple summary I've written which might help.  Keep in mind, this is just a high-level conceptual overview where I try to avoid getting bogge…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question