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.
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?
Does this work for you?
echo Call RMLogEvent.bat %%ErrorLevel%% RenameComputersList executed %%Date%% %%Time%% >> .\RenameComputersList.bat
Yes, that works perfectly. I was clueless... Thank you!!