I wrote a basic batch file to add couple of domain groups to the local admin account, validate the groups have been added, and change the color of the output based on the result. I'm sure there are much better ways to do this using VBS or other programming language but I wanted to know if there is a better way to do it using CMD only without any other third party tool.
I want to know if there is a way to display both outputs at the same time using different colors on the screen. For example, if one domain group was added successfully but the other one failed for whatever reason, are you able to display the output of the successful one in one color (green) and the output of the failed on in another color (red) without changing the color of the entire CMD window?
Below is my code:
@echo off
net localgroup administrators /add DOMAIN GROUP 1 >nul
if %errorlevel% == 0 (
color 0A
echo DOMAIN GROUP 1 group was added successfully!
) else (
color 0C
echo DOMAIN GROUP 1 group was not added!
)
echo.
pause
cls
net localgroup administrators /add DOMAIN GROUP 2 >nul
if %errorlevel% == 0 (
color 0A
echo DOMAIN GROUP 2 group was added successfully!
) else (
color 0C
echo DOMAIN GROUP 2 group was not added!
)
echo.
pause