Skip to content

Instantly share code, notes, and snippets.

@VimalShekar
Created April 26, 2018 06:21
Show Gist options
  • Save VimalShekar/739bc45dde86c1e2836c1361c26623d7 to your computer and use it in GitHub Desktop.
Save VimalShekar/739bc45dde86c1e2836c1361c26623d7 to your computer and use it in GitHub Desktop.
Read the OS version and description in a batch script.
REM read OS version x.y.z.p
for /f "usebackq tokens=*" %%n in (`WMIC.exe os get Version ^| findstr /v /r "^$"`) do (
SET OSVersion=%%n )
 
REM read Description : Ex: Windows 10 Professional N
for /f "usebackq tokens=*" %%n in (`WMIC.exe os get Caption ^| findstr /v /r "^$"`) do (
SET OSName=%%n )
 
REM read type... 1=> workstation, 2=> domain controller , 3=> server
for /f "usebackq tokens=*" %%n in (`WMIC.exe os get ProductType ^| findstr /v /r "^$"`) do (
SET OSType=%%n )
 
 
REM read architecture. Can be 32-bit or 64-bit
for /f "usebackq tokens=*" %%n in (`WMIC.exe os get OSArchitecture ^| findstr /v /r "^$"`) do (
SET OSArch=%%n )
 
 
for /f "usebackq tokens=*" %n in (`WMIC.exe os get OSArchitecture ^| findstr /v /r "^$"`) do (
SET OSArch=%n )
 
ECHO Detected OSVersion:%OSVersion%; OSName:%OSName%; OSType=%OSType%; OSArch=%OSArch%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment