Wednesday, February 20, 2013

Shell Script Find Windows Version and Architecture

Problem: I need to find a script to find version and processor architecture windows in a windows shell script.

Soltuion: 

Batch/CMD Script
:; Find Windows Version and ArchitectureFOR /F "tokens=*" %%i in ('VER') do SET WinVer=%%i FOR /F "tokens=1-3 delims=]-" %%A IN ("%WinVer%" ) DO ( SET VarString=%%A )
FOR /F "tokens=1-9 delims=n" %%A IN ("%VarString%" ) DO ( SET WinVer=%%C)
FOR /F "tokens=1-8 delims=.- " %%A IN ("%WinVer%" ) DO (SET WinMajor=%%ASET WinMinor=%%B)
:; Set version+archicitecher string. 5.1.x86 is Windows XP x86, 6.1.x86 is Windows 7 x86, & 6.1.AMD64 is Windows 7 x64SET VerArch=%WinMajor%.%WinMinor%.%processor_architecture% 
 Powershell
# Find processor architecture and Windows version$processorArchitecture = (Get-ItemProperty 'HKLM:\SYSTEM\ControlSet001\Control\Session Manager\Environment').PROCESSOR_ARCHITECTURE$windowsVersion = (Get-WmiObject Win32_OperatingSystem).Version | %{$data = $_.split("."); Write-Output "$($data[0]).$($data[1])"}


No comments: