Currently Being Moderated

How to Add Local Users and Groups with a Batch File Distribution Package

VERSION 3

Created on: Jan 26, 2008 12:27 PM by rhyous - Last Modified:  Apr 21, 2008 4:52 PM by rhyous

Adding a Local User

A batch file can be used to add a local user to many machines at once.

 

The following is a sample batch file that will accomplish this task.

 

REM Add a user batch file

net user john1 passwd! /add

 

However, maybe you do not want the username and password in the batch file in clear text. That batch file will hang out in the ldclient\SDMCache for a short time, as well as being echoed to the sdclient_task#.log in the ldclient\data directory.

 

So you can store the password in the command line of the Distribution Package.

 

REM Add a user
REM %1 is the username
REM %2 is the password

REM Turn echo off so the password is not echoed to the log
@echo off
net user %1 %2 /add

 

Now in the distribution package simply put the username and the password in the command line.  The password is still clear text in the Distribution Package, but only LANDesk administrators can see that so there is more security there.

 

Deleting a Local User

To delete a user, it is just as simple.

 

REM Add a user batch file

net user John1 /delete

 

 

Adding Local Users from a .CSV File

Here is an simply one command in a batch file that will add all the users from a .csv file.

 

REM Add all the users from a .csv file

REM Turn echo off so the passwords are not echoed to the log
@echo off
FOR /F "tokens=1,2 delims=," %%a IN (users.csv) DO net user %1 %1 /add

REM Now delete the .csv file.  We need to delete it, it has clear text passwords
del /F /Q users.csv

 

The .csv file would look like this:

 


John,passwd!1234
Jane,passwd!1234
Jared,passwd!1234

 

Adding a Local Group

Use the following batch file to add a local group.

 

REM Adding a local group

net localgroup MyGroup /Comment:"My own Group" /add

 

Deleting a local Group

Use the following batch file to delete a local group.

 

REM Adding a local group

net localgroup MyGroup /delete

 

Adding a User to a Local Group.

Use the following batch file to add a user to a local group.

REM Adding a user to a local group

net localgroup MyGroup john /add

 

Deleting a User from a Local Group.

Use the following batch file to delete a user from a local group.

REM Deleting a user to a local group

net localgroup MyGroup john /delete

 

Managing a Local Administrator Account in Workgroup Enviroments

It may be beneficial, especially in Workgroup environments, to have the a local administrator account that has the same username and password on all workstations.

 

This can be done with this batch file.

REM Adding a local administrator
REM Turn echo off
@ECHO OFF

REM Add the user
net user ITAdmin %1 /add
REM Put the password in the distribution package's command line

REM Add the user to the group
net localgroup administrators ITAdmin /add

REM Remove the user from the default "users" group
net localgroup users ITAdmin /delete

 

rhyous rhyous  says:

The password appears to be logged in Clear text in these logs:

- LANDesk\shared files\ServiceHost.log

- LANDesk\ldclient\data\sdclient_task##.log

 

You may want to delete have the batch file delete those two files or you may want to use a tool like like bat2exe (do a google search for bat2exe) so that the passwords are not in clear text.

LANDesk Community powered by Jive Software's Clearspace ® Subscribe| Legal Notices| Investor Relations| Avocent| Privacy Policy © 2009 LANDesk Software