You are not logged in.

#1 16 Nov 2016 22:50

paul0041
Member
Registered: 19 Mar 2015
Posts: 21

Using script to write commands to new script

I want to rename a whole bunch of computers and would like them to log back to the server that they have renamed themselves.

Step 1: (this part works)
For /F "Tokens=1-2 delims=," %%i IN ( .\CorrectedMachineNames.csv ) Do (
    echo WMIC ComputerSystem where Name="%%i" CALL RENAME Name="%%j" >> .\RenameComputersList.bat
    )

The code above creates a script that has many lines that look just like this:
WMIC ComputerSystem where Name="1811900-F-15850" CALL RENAME Name="1811900-F15850"

When a computer finds that its current name matches the first name in the above line, it renames itself.
All Good to this point.


Step 2:
Now I want the script that creates RenameComputersList.bat to include this line at the end so RenameComputersList.bat will log back to the server:

Call RMLogEvent.bat %ErrorLevel% "RenameComputersList executed %Date% %Time%"


I have tried using carrots to get the % characters to write to the file like this:
echo Call RMLogEvent.bat ^%ErrorLevel^% RenameComputersList executed ^%Date^% ^%Time^% >> .\RenameComputersList.bat
but this fails to write the variables at all.  Percent sign and variable name are missing from the resulting script.

maybe there is an easier way?

Offline

#2 16 Nov 2016 23:11

ImAhNoBoDy
Member
Registered: 29 Dec 2015
Posts: 12

Re: Using script to write commands to new script

Does this work for you?

echo Call RMLogEvent.bat %%ErrorLevel%% RenameComputersList executed %%Date%% %%Time%% >> .\RenameComputersList.bat

Offline

#3 16 Nov 2016 23:19

paul0041
Member
Registered: 19 Mar 2015
Posts: 21

Re: Using script to write commands to new script

Yes, that works perfectly.  I was clueless... Thank you!!

Offline

Board footer

Powered by