James Korden
James Korden

Reputation: 634

Sending a command to a range of IP's using PSEXEC and a Batch file

I'm trying to send an unlock command to remote computers. All computers are on the same subnet and an upper and lower IP will be provided at run time.

I have constructed the following:

:range
echo.
set /a ip=xxx.xxx.xxx
echo Please input lower IP range.
set /p lower=%ip%
echo.
echo Please input upper IP range.
set /p upper=%ip%
set /a lip=
echo.


:loop
set lip = %ip%%lower%
psexec \\%lip% -u .\<redacted> -p <redacted> Net user <redacted> /Active:yes
if %lower%==%upper% goto loopend
set /a lower=%lower%+1
goto loop

:loopend
goto end

This gives me a lot of errors. Firstly, I understood set lip = %ip%%lower% would concatenate the two. I'm not certain they are being processed as strings, however. How can this be resolved?

If I echo %ip% I only see the first part of the IP (before the first .). Clearly this data isn't being stored correctly. I tried enclosing it in speech marks with no success (it says Missing operator).

I am open to any radically different solutions if you feel I am making a pigs ear of this.

Upvotes: 0

Views: 2630

Answers (1)

aphoria
aphoria

Reputation: 20179

You need to add a . between the parts of your IP address.

set lip=%ip%.%lower%

You can add an ECHO statement right after the above line to make sure the IP looks right.

ECHO %lip%

UPDATE

You also need to remove the /a from this line:

set /a ip=xxx.xxx.xxx

It should just be:

set ip=xxx.xxx.xxx

Upvotes: 3

Related Questions