?
Solved

Script to automate additon/removal of users

Posted on 2003-03-25
15
Medium Priority
?
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +2
15 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 85

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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Have you ever set up your wireless router at home or in the office to find that you little pop-up bubble in the bottom right-hand corner of Windows read "IP Conflict - One of more computers on the network have been assigned the following IP address"…
Greetings, Experts! First let me state that this website is top notch. I thoroughly enjoy the community that is shared here; those seeking help and those willing to sacrifice their time to help. It is fantastic. I am writing this article at th…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
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…

765 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