The problem with PowerShell is that sometimes you can’t use it

PowerShell puts the fun back in scripting and it's horrfying but every now and again I'm forced to write a good old batch script.  Batch is good enough to get most jobs done it's just not as "fun" as PowerShell.  Recently it came up in an internal alias about how to detect if you're running on Vista from a batch script. 

for /f "tokens=4 delims=.] " %%i in ('ver') do set OSVERSION=%%i

This parses the output of the "ver" command in batch and gives back the result.  If %OSVERSION% is 6 then you're on Vista.

Comments (2)

  1. ie_hater22 says:

    wow, you can almost get the version almost as easily as

    uname -a | grep -oE "[0-9]+.([0-9]+.?)+"

    example run:

    $>uname -a | grep -oE "[0-9]+.([0-9]+.?)+"

  2. Mathias says:

    ie_hater: Did you notice that this blog post was about the "old" (non-powershell) way to get the OS version?

    With PS, it’s much easier and does not require any regex knowledge or string parsing.

    Here are some examples:

    PS C:UsersMathias> [Environment]

    IsPublic IsSerial Name                                     BaseType

    ——– ——– —-                                     ——–

    True     False    Environment                              System.Object

    PS C:UsersMathias> [Environment]::OsVersion

                        Platform ServicePack                   Version                       VersionString

                        ——– ———–                   ——-                       ————-

                         Win32NT                               6.0.6000.0                    Microsoft Windows NT 6.0.6…

    PS C:UsersMathias> [Environment]::OsVersion.VersionString

    Microsoft Windows NT 6.0.6000.0

    PS C:UsersMathias> [Environment]::OsVersion.Version

    Major  Minor  Build  Revision

    —–  —–  —–  ——–

    6      0      6000   0

    PS C:UsersMathias> [Environment]::OsVersion.Version.Major


Skip to main content