I had to work out a few things to do in a batch file the last couple of days so I thought I would share. Note: so this doesn’t become a huge powershell versus perl versus whatever discussion, I had no choice, I had batch available period and even that was possibly stretching it a little as the people involved seemed very concerned about scripts, etc. Also, yes I am aware of Tim–Toadie (TIMTOWTDI). So please feel free to comment with additional methods.
Getting date and time in a useful format
for /f "tokens=1-4 Delims=/ " %%i in (‘date /t’) do set dt=%%l/%%j/%%k
for /f "tokens=1" %%i in (‘time /t’) do set tm=%%i
echo Date: %dt%-%tm%
Is this machine virtual or physical? It could be VMWare, HyperV or Virtual Server or Virtual PC. I don’t have the strings for other virtualization techs, if people are using them and can post the results of the command “wmic computersystem get model” then they can be added to the batch commands.
set VIRTUAL=NO
set VMWARE=NO
set HYPERV=NO
for /f "skip=2 tokens=1-2 delims=," %%i in (‘wmic computersystem get model /format:csv’) do set MODEL=%%j: Microsoft Virtualization
if "%MODEL%"=="Virtual Machine" (
set VIRTUAL=YES
set HYPERV=YES
): VMWare Virtualization
if "%MODEL%"=="VMware Virtual Platform" (
set VIRTUAL=YES
set VMWARE=YES
)
Is this machine Vista or better?
SET VISTA+=NO
if exist %systemroot%\system32\bcdedit.exe set VISTA+=YES
Is this machine x64?
SET x64=NO
if exist "%systemdrive%\program files (x86)" set x64=YES