Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch File Creation help needed  (Read 2161 times)

0 Members and 1 Guest are viewing this topic.

rhino8

  • Guest
Batch File Creation help needed
« on: October 16, 2006, 05:42:52 AM »
Hi,

I am kind of new to batch file creation. I am trying to reset the passwords to about 40 odd servers on our network. Rather than doing this manually I thought I would try to do this via a batch file, I am also hoping to run disk defrag and to an anti-virus scan this way also:

I have created a batch file, see contents below:

for /F "delims= " %%i IN (c:\Scripting\Servers.txt) DO (c:\Scripting\rcmd.exe net user administrator testpassw0rd >> c:\Password.txt)
Pause

The file mentioned Servers.txt is a list of servers listed as follows:

\\lvpwpnas01
\\lvpwpnas02
etc...etc

When I look at the password.txt file once this has been run I get the following result:

"
Usage: rcmd [server_name [command] ]

Prompts for server_name if  not supplied.   Session is
interactive and is terminated by ctrl-Break or Exit of
remote shell.   Program is terminated by ctrl-Break or
ctrl-C when no session is in progress.

If no command supplied,  session is interactive and is
terminated by ctrl-Break  or Exit  of remote cmd shell

If command is supplied,  remote shell executes  single
command on specified server and exits.

Note : Command line server_name requires leading '\\'s"

Any help would be great...  Where am I going wrong?

Kind Regards, Lee  

QBasicMac

  • Guest
Re: Batch File Creation help needed
« Reply #1 on: October 16, 2006, 07:50:51 AM »
Quote
for /F "delims= " %%i IN (c:\Scripting\Servers.txt) DO (c:\Scripting\rcmd.exe net user administrator testpassw0rd >> c:\Password.txt)

Kind of lost me, buddy. What do you expect "delims" to do? Your file apparently has no delimiters. Well, anyway, I guess it doesn't hurt anything.

But you have no %%i inside the DO. So all you will do is repeat the DO as many times as there are lines in your data.

Try this to see what I mean:
for /F  %%i IN (c:\Scripting\Servers.txt) DO (echo MyStuff: %%i)
if you omit the %%i, you just get MyStuff repeated.

How about just explain what you would do if there was no BAT file and you were going to sit and enter stuff 40 times. Would you enter this command list:
c:\Scripting\rcmd.exe net user administrator \\lvpwpnas01 >> c:\Password.txt
c:\Scripting\rcmd.exe net user administrator \\lvpwpnas02 >>c:\Password.txt
... (etc.)?

Forget about BAT files and come up with a list of 40 commands that do what you want. (Of course, start with messing with only 2 servers). When you have them, simply put them in a BAT file and run them. Do it the straightforward way with no tricky FOR-stuff. Then later develop tricky stuff if you just want to play around.

Mac

GuruGary



    Adviser
    Re: Batch File Creation help needed
    « Reply #2 on: October 16, 2006, 02:44:24 PM »
    I think QBasicMac is right ... you forgot to use  your %%i.  Try this:
    Code: [Select]
    for /F "delims= " %%i IN (c:\Scripting\Servers.txt) DO c:\Scripting\rcmd.exe %%i net user administrator testpassw0rd >> c:\Password.txt
    Pause