Windows Vista Forums

Reliable way to get Windows Version?

  1. #1


    Charlie Russel - MVP Guest

    Reliable way to get Windows Version?

    I need a way to determine what Windows version and edition a script is
    running on. I can get the build number, that's trivial:

    $Build=(get-item 'HKLM:/Software/Microsoft/Windows
    NT/CurrentVersion').getvalue('CurrentBuildNumber')



    But it doesn't much help when Windows Vista SP1 is 6001 and so is Windows
    Server 2008. And also doesn't tell me which edition. The ProductID:

    $ProductID=(get-item 'HKLM:/Software/Microsoft/Windows
    NT/CurrentVersion').getvalue('ProductID')

    could probably do it, but I'm not at all sure what I'm looking at there, and
    how to parse it for what's important. First, does anyone know a reference
    that gives the relevant numbers for the various editions of Windows. And
    second, could someone suggest a regex to parse it into consituent parts? Or,
    alternately, does someone have a better location to get the version and
    edition of Windows?

    Thanks,

    --
    Charlie.
    http://msmvps.com/xperts64
    http://mvp.support.microsoft.com/profile/charlie.russel



      My System SpecsSystem Spec

  2. #2


    Jon Guest

    Re: Reliable way to get Windows Version?

    "Charlie Russel - MVP" <charlie@xxxxxx> wrote in message
    news:6116302E-00CF-46C6-A17B-4F35EA5575C9@xxxxxx

    >I need a way to determine what Windows version and edition a script is
    >running on. I can get the build number, that's trivial:
    >
    > $Build=(get-item 'HKLM:/Software/Microsoft/Windows
    > NT/CurrentVersion').getvalue('CurrentBuildNumber')
    >
    > But it doesn't much help when Windows Vista SP1 is 6001 and so is Windows
    > Server 2008. And also doesn't tell me which edition. The ProductID:
    >
    > $ProductID=(get-item 'HKLM:/Software/Microsoft/Windows
    > NT/CurrentVersion').getvalue('ProductID')
    >
    > could probably do it, but I'm not at all sure what I'm looking at there,
    > and how to parse it for what's important. First, does anyone know a
    > reference that gives the relevant numbers for the various editions of
    > Windows. And second, could someone suggest a regex to parse it into
    > consituent parts? Or, alternately, does someone have a better location to
    > get the version and edition of Windows?
    >


    There are a number of ways you could get relevant information. Parsing the
    product id sounds a bit of an extreme approach imho ;-) [although possible
    and worth a thread in itself]

    From the registry as you mentioned under

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

    (Get-Item "HKLM:SOFTWARE\Microsoft\Windows
    NT\CurrentVersion").GetValue("ProductName")
    (Get-Item "HKLM:SOFTWARE\Microsoft\Windows
    NT\CurrentVersion").GetValue("EditionID")

    would distinguish between Windows Server 2008 and Vista

    Other options ..
    (Get-Item "HKLM:SOFTWARE\Microsoft\Windows
    NT\CurrentVersion").GetValueNames()



    or you could use Win32_OperatingSystem

    Get-WmiObject Win32_OperatingSystem | fl -property *

    eg

    (Get-WmiObject Win32_OperatingSystem).Caption
    (Get-WmiObject Win32_OperatingSystem).BuildNumber

    OR

    [environment]:sversion

    eg

    [environment]:sversion.Version.ToString()

    and split further....


    [environment]:sversion.Version.Major
    [environment]:sversion.Version.Minor
    [environment]:sversion.Version.Build
    [environment]:sversion.Version.Revision


    A combination of the above should provide you with sufficient information.



    --
    Jon




      My System SpecsSystem Spec

  3. #3


    Shay Levi Guest

    Re: Reliable way to get Windows Version?


    You can also try the plain old DOS ver command:


    # on XP box
    PS> cmd /c ver
    Microsoft Windows XP [Version 5.1.2600]

    # on Win2003 server R2 x64
    PS> cmd /c ver
    Microsoft Windows [Version 5.2.3790]

    # on Windows 2000 STD Server SP4
    PS> cmd /c ver
    Microsoft Windows 2000 [Version 5.00.2195]




    -----
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com

    > I need a way to determine what Windows version and edition a script is
    > running on. I can get the build number, that's trivial:
    >
    > $Build=(get-item 'HKLM:/Software/Microsoft/Windows
    > NT/CurrentVersion').getvalue('CurrentBuildNumber')
    >
    > But it doesn't much help when Windows Vista SP1 is 6001 and so is
    > Windows Server 2008. And also doesn't tell me which edition. The
    > ProductID:
    >
    > $ProductID=(get-item 'HKLM:/Software/Microsoft/Windows
    > NT/CurrentVersion').getvalue('ProductID')
    >
    > could probably do it, but I'm not at all sure what I'm looking at
    > there, and how to parse it for what's important. First, does anyone
    > know a reference that gives the relevant numbers for the various
    > editions of Windows. And second, could someone suggest a regex to
    > parse it into consituent parts? Or, alternately, does someone have a
    > better location to get the version and edition of Windows?
    >
    > Thanks,
    >


      My System SpecsSystem Spec

  4. #4


    Andy Schneider Guest

    Re: Reliable way to get Windows Version?

    get-wmiobject win32_operatingsystem

    This will give you BuildNumber and Version

    Andy
    http://get-powershell.com




    "Charlie Russel - MVP" <charlie@xxxxxx> wrote in message
    news:6116302E-00CF-46C6-A17B-4F35EA5575C9@xxxxxx

    >I need a way to determine what Windows version and edition a script is
    >running on. I can get the build number, that's trivial:
    >
    > $Build=(get-item 'HKLM:/Software/Microsoft/Windows
    > NT/CurrentVersion').getvalue('CurrentBuildNumber')
    >
    > But it doesn't much help when Windows Vista SP1 is 6001 and so is Windows
    > Server 2008. And also doesn't tell me which edition. The ProductID:
    >
    > $ProductID=(get-item 'HKLM:/Software/Microsoft/Windows
    > NT/CurrentVersion').getvalue('ProductID')
    >
    > could probably do it, but I'm not at all sure what I'm looking at there,
    > and how to parse it for what's important. First, does anyone know a
    > reference that gives the relevant numbers for the various editions of
    > Windows. And second, could someone suggest a regex to parse it into
    > consituent parts? Or, alternately, does someone have a better location to
    > get the version and edition of Windows?
    >
    > Thanks,
    >
    > --
    > Charlie.
    > http://msmvps.com/xperts64
    > http://mvp.support.microsoft.com/profile/charlie.russel
    >
    >

      My System SpecsSystem Spec

  5. #5


    Charlie Russel - MVP Guest

    Re: Reliable way to get Windows Version?

    No help - returns the same for any version of Vista with SP1 as it does for
    Server 2008 RTM. But a good way to get the build number, certainly.

    --
    Charlie.
    http://msmvps.com/xperts64
    http://mvp.support.microsoft.com/profile/charlie.russel


    "Andy Schneider" <andy@xxxxxx-powershell.com> wrote in message
    news:9265C697-5DE4-4C8E-BAD3-B8023214FA79@xxxxxx

    > get-wmiobject win32_operatingsystem
    >
    > This will give you BuildNumber and Version
    >
    > Andy
    > http://get-powershell.com
    >
    >
    >
    >
    > "Charlie Russel - MVP" <charlie@xxxxxx> wrote in message
    > news:6116302E-00CF-46C6-A17B-4F35EA5575C9@xxxxxx

    >>I need a way to determine what Windows version and edition a script is
    >>running on. I can get the build number, that's trivial:
    >>
    >> $Build=(get-item 'HKLM:/Software/Microsoft/Windows
    >> NT/CurrentVersion').getvalue('CurrentBuildNumber')
    >>
    >> But it doesn't much help when Windows Vista SP1 is 6001 and so is Windows
    >> Server 2008. And also doesn't tell me which edition. The ProductID:
    >>
    >> $ProductID=(get-item 'HKLM:/Software/Microsoft/Windows
    >> NT/CurrentVersion').getvalue('ProductID')
    >>
    >> could probably do it, but I'm not at all sure what I'm looking at there,
    >> and how to parse it for what's important. First, does anyone know a
    >> reference that gives the relevant numbers for the various editions of
    >> Windows. And second, could someone suggest a regex to parse it into
    >> consituent parts? Or, alternately, does someone have a better location to
    >> get the version and edition of Windows?
    >>
    >> Thanks,
    >>
    >> --
    >> Charlie.
    >> http://msmvps.com/xperts64
    >> http://mvp.support.microsoft.com/profile/charlie.russel
    >>
    >>
    >

      My System SpecsSystem Spec

  6. #6


    Charlie Russel - MVP Guest

    Re: Reliable way to get Windows Version?

    Won't help - returns the exact same for Server 2008 and Vista with SP1. (and
    has the same problem with XP x64 and Server 2003 SP1). And doesn't give me
    edition so I can branch on features available.

    --
    Charlie.
    http://msmvps.com/xperts64
    http://mvp.support.microsoft.com/profile/charlie.russel


    "Shay Levi" <no@xxxxxx> wrote in message
    news:8766a94423a778ca5635947a6762@xxxxxx

    >
    > You can also try the plain old DOS ver command:
    >
    >
    > # on XP box
    > PS> cmd /c ver
    > Microsoft Windows XP [Version 5.1.2600]
    >
    > # on Win2003 server R2 x64
    > PS> cmd /c ver Microsoft Windows [Version 5.2.3790]
    >
    > # on Windows 2000 STD Server SP4
    > PS> cmd /c ver
    > Microsoft Windows 2000 [Version 5.00.2195]
    >
    >
    >
    >
    > -----
    > Shay Levi
    > $cript Fanatic
    > http://scriptolog.blogspot.com
    >

    >> I need a way to determine what Windows version and edition a script is
    >> running on. I can get the build number, that's trivial:
    >>
    >> $Build=(get-item 'HKLM:/Software/Microsoft/Windows
    >> NT/CurrentVersion').getvalue('CurrentBuildNumber')
    >>
    >> But it doesn't much help when Windows Vista SP1 is 6001 and so is
    >> Windows Server 2008. And also doesn't tell me which edition. The
    >> ProductID:
    >>
    >> $ProductID=(get-item 'HKLM:/Software/Microsoft/Windows
    >> NT/CurrentVersion').getvalue('ProductID')
    >>
    >> could probably do it, but I'm not at all sure what I'm looking at
    >> there, and how to parse it for what's important. First, does anyone
    >> know a reference that gives the relevant numbers for the various
    >> editions of Windows. And second, could someone suggest a regex to
    >> parse it into consituent parts? Or, alternately, does someone have a
    >> better location to get the version and edition of Windows?
    >>
    >> Thanks,
    >>
    >
    >

      My System SpecsSystem Spec

  7. #7


    Andy Schneider Guest

    Re: Reliable way to get Windows Version?

    Sorry.. thats what I get for trying to answer questions before I finish my
    coffee in the morning

    Andy


    "Charlie Russel - MVP" <charlie@xxxxxx> wrote in message
    news:FD2A2D4F-5746-4237-9E9B-B177780C81C8@xxxxxx

    > No help - returns the same for any version of Vista with SP1 as it does
    > for Server 2008 RTM. But a good way to get the build number, certainly.
    >
    > --
    > Charlie.
    > http://msmvps.com/xperts64
    > http://mvp.support.microsoft.com/profile/charlie.russel
    >
    >
    > "Andy Schneider" <andy@xxxxxx-powershell.com> wrote in message
    > news:9265C697-5DE4-4C8E-BAD3-B8023214FA79@xxxxxx

    >> get-wmiobject win32_operatingsystem
    >>
    >> This will give you BuildNumber and Version
    >>
    >> Andy
    >> http://get-powershell.com
    >>
    >>
    >>
    >>
    >> "Charlie Russel - MVP" <charlie@xxxxxx> wrote in message
    >> news:6116302E-00CF-46C6-A17B-4F35EA5575C9@xxxxxx

    >>>I need a way to determine what Windows version and edition a script is
    >>>running on. I can get the build number, that's trivial:
    >>>
    >>> $Build=(get-item 'HKLM:/Software/Microsoft/Windows
    >>> NT/CurrentVersion').getvalue('CurrentBuildNumber')
    >>>
    >>> But it doesn't much help when Windows Vista SP1 is 6001 and so is
    >>> Windows Server 2008. And also doesn't tell me which edition. The
    >>> ProductID:
    >>>
    >>> $ProductID=(get-item 'HKLM:/Software/Microsoft/Windows
    >>> NT/CurrentVersion').getvalue('ProductID')
    >>>
    >>> could probably do it, but I'm not at all sure what I'm looking at there,
    >>> and how to parse it for what's important. First, does anyone know a
    >>> reference that gives the relevant numbers for the various editions of
    >>> Windows. And second, could someone suggest a regex to parse it into
    >>> consituent parts? Or, alternately, does someone have a better location
    >>> to get the version and edition of Windows?
    >>>
    >>> Thanks,
    >>>
    >>> --
    >>> Charlie.
    >>> http://msmvps.com/xperts64
    >>> http://mvp.support.microsoft.com/profile/charlie.russel
    >>>
    >>>
    >>
    >

      My System SpecsSystem Spec

  8. #8


    Charlie Russel - MVP Guest

    Re: Reliable way to get Windows Version?

    Yes, that will do nearly all I need, on a Vista / Server 2008 system (though
    doesn't tell me VL v. Retail, but I can live without that). However, it
    doesn't cut it on Server 2003 / Windows XP x64 (where Edition isn't
    available) and doesn't tell me if I'm on SBS or Server, much less which
    version of Server. There I've used -matches "76588-" on the Product ID to
    tell me it's Windows XP x64, since there is only a single version of it. But
    that's fairly ugly, and doesn't lend itself to doing math on it or building
    a simple (<g>) switch statement.

    I fear we may be back to parsing ProductID to get everything...

    --
    Charlie.
    http://msmvps.com/xperts64
    http://mvp.support.microsoft.com/profile/charlie.russel


    "Jon" <Email_Address@xxxxxx> wrote in message
    news:%239YXVaAiIHA.4744@xxxxxx

    > "Charlie Russel - MVP" <charlie@xxxxxx> wrote in message
    > news:6116302E-00CF-46C6-A17B-4F35EA5575C9@xxxxxx

    >>I need a way to determine what Windows version and edition a script is
    >>running on. I can get the build number, that's trivial:
    >>
    >> $Build=(get-item 'HKLM:/Software/Microsoft/Windows
    >> NT/CurrentVersion').getvalue('CurrentBuildNumber')
    >>
    >> But it doesn't much help when Windows Vista SP1 is 6001 and so is Windows
    >> Server 2008. And also doesn't tell me which edition. The ProductID:
    >>
    >> $ProductID=(get-item 'HKLM:/Software/Microsoft/Windows
    >> NT/CurrentVersion').getvalue('ProductID')
    >>
    >> could probably do it, but I'm not at all sure what I'm looking at there,
    >> and how to parse it for what's important. First, does anyone know a
    >> reference that gives the relevant numbers for the various editions of
    >> Windows. And second, could someone suggest a regex to parse it into
    >> consituent parts? Or, alternately, does someone have a better location to
    >> get the version and edition of Windows?
    >>
    >
    >
    >
    > There are a number of ways you could get relevant information. Parsing the
    > product id sounds a bit of an extreme approach imho ;-) [although
    > possible and worth a thread in itself]
    >
    > From the registry as you mentioned under
    >
    > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
    >
    > (Get-Item "HKLM:SOFTWARE\Microsoft\Windows
    > NT\CurrentVersion").GetValue("ProductName")
    > (Get-Item "HKLM:SOFTWARE\Microsoft\Windows
    > NT\CurrentVersion").GetValue("EditionID")
    >
    > would distinguish between Windows Server 2008 and Vista
    >
    > Other options ..
    > (Get-Item "HKLM:SOFTWARE\Microsoft\Windows
    > NT\CurrentVersion").GetValueNames()
    >
    >
    >
    > or you could use Win32_OperatingSystem
    >
    > Get-WmiObject Win32_OperatingSystem | fl -property *
    >
    > eg
    >
    > (Get-WmiObject Win32_OperatingSystem).Caption
    > (Get-WmiObject Win32_OperatingSystem).BuildNumber
    >
    > OR
    >
    > [environment]:sversion
    >
    > eg
    >
    > [environment]:sversion.Version.ToString()
    >
    > and split further....
    >
    >
    > [environment]:sversion.Version.Major
    > [environment]:sversion.Version.Minor
    > [environment]:sversion.Version.Build
    > [environment]:sversion.Version.Revision
    >
    >
    > A combination of the above should provide you with sufficient information.
    >
    >
    >
    > --
    > Jon
    >
    >
    >

      My System SpecsSystem Spec

  9. #9


    Andy Schneider Guest

    Re: Reliable way to get Windows Version?

    How about gwmi win32_operatingsystem | select Name

    - From 2008 RTM
    PS C:\Users\superandys> gwmi win32_operatingSystem | select name

    name
    ----
    Microsoft® Windows Server® 2008 Enterprise
    |C:\Windows|\Device\Harddisk0\Partition2



    From Vista Ultimate
    PS C:\Users\superandys>


    PS 2 > gwmi win32_operatingSystem | Select Name

    Name
    ----
    Microsoft® Windows VistaT Ultimate |C:\Windows|\Device\Harddisk0\Partition1


    PS 3 >




    "Charlie Russel - MVP" <charlie@xxxxxx> wrote in message
    news:FD2A2D4F-5746-4237-9E9B-B177780C81C8@xxxxxx

    > No help - returns the same for any version of Vista with SP1 as it does
    > for Server 2008 RTM. But a good way to get the build number, certainly.
    >
    > --
    > Charlie.
    > http://msmvps.com/xperts64
    > http://mvp.support.microsoft.com/profile/charlie.russel
    >
    >
    > "Andy Schneider" <andy@xxxxxx-powershell.com> wrote in message
    > news:9265C697-5DE4-4C8E-BAD3-B8023214FA79@xxxxxx

    >> get-wmiobject win32_operatingsystem
    >>
    >> This will give you BuildNumber and Version
    >>
    >> Andy
    >> http://get-powershell.com
    >>
    >>
    >>
    >>
    >> "Charlie Russel - MVP" <charlie@xxxxxx> wrote in message
    >> news:6116302E-00CF-46C6-A17B-4F35EA5575C9@xxxxxx

    >>>I need a way to determine what Windows version and edition a script is
    >>>running on. I can get the build number, that's trivial:
    >>>
    >>> $Build=(get-item 'HKLM:/Software/Microsoft/Windows
    >>> NT/CurrentVersion').getvalue('CurrentBuildNumber')
    >>>
    >>> But it doesn't much help when Windows Vista SP1 is 6001 and so is
    >>> Windows Server 2008. And also doesn't tell me which edition. The
    >>> ProductID:
    >>>
    >>> $ProductID=(get-item 'HKLM:/Software/Microsoft/Windows
    >>> NT/CurrentVersion').getvalue('ProductID')
    >>>
    >>> could probably do it, but I'm not at all sure what I'm looking at there,
    >>> and how to parse it for what's important. First, does anyone know a
    >>> reference that gives the relevant numbers for the various editions of
    >>> Windows. And second, could someone suggest a regex to parse it into
    >>> consituent parts? Or, alternately, does someone have a better location
    >>> to get the version and edition of Windows?
    >>>
    >>> Thanks,
    >>>
    >>> --
    >>> Charlie.
    >>> http://msmvps.com/xperts64
    >>> http://mvp.support.microsoft.com/profile/charlie.russel
    >>>
    >>>
    >>
    >

      My System SpecsSystem Spec

  10. #10


    Charlie Russel - MVP Guest

    Re: Reliable way to get Windows Version?

    no, that's OK - it gave me another way to look at it, that's always useful.

    --
    Charlie.
    http://msmvps.com/xperts64
    http://mvp.support.microsoft.com/profile/charlie.russel


    "Andy Schneider" <andy@xxxxxx-powershell.com> wrote in message
    news:ECF7AE5A-C0C4-4CBA-AC1F-FF9318B96557@xxxxxx

    > Sorry.. thats what I get for trying to answer questions before I finish my
    > coffee in the morning
    >
    > Andy
    >
    >
    > "Charlie Russel - MVP" <charlie@xxxxxx> wrote in message
    > news:FD2A2D4F-5746-4237-9E9B-B177780C81C8@xxxxxx

    >> No help - returns the same for any version of Vista with SP1 as it does
    >> for Server 2008 RTM. But a good way to get the build number, certainly.
    >>
    >> --
    >> Charlie.
    >> http://msmvps.com/xperts64
    >> http://mvp.support.microsoft.com/profile/charlie.russel
    >>
    >>
    >> "Andy Schneider" <andy@xxxxxx-powershell.com> wrote in message
    >> news:9265C697-5DE4-4C8E-BAD3-B8023214FA79@xxxxxx

    >>> get-wmiobject win32_operatingsystem
    >>>
    >>> This will give you BuildNumber and Version
    >>>
    >>> Andy
    >>> http://get-powershell.com
    >>>
    >>>
    >>>
    >>>
    >>> "Charlie Russel - MVP" <charlie@xxxxxx> wrote in
    >>> message news:6116302E-00CF-46C6-A17B-4F35EA5575C9@xxxxxx
    >>>>I need a way to determine what Windows version and edition a script is
    >>>>running on. I can get the build number, that's trivial:
    >>>>
    >>>> $Build=(get-item 'HKLM:/Software/Microsoft/Windows
    >>>> NT/CurrentVersion').getvalue('CurrentBuildNumber')
    >>>>
    >>>> But it doesn't much help when Windows Vista SP1 is 6001 and so is
    >>>> Windows Server 2008. And also doesn't tell me which edition. The
    >>>> ProductID:
    >>>>
    >>>> $ProductID=(get-item 'HKLM:/Software/Microsoft/Windows
    >>>> NT/CurrentVersion').getvalue('ProductID')
    >>>>
    >>>> could probably do it, but I'm not at all sure what I'm looking at
    >>>> there, and how to parse it for what's important. First, does anyone
    >>>> know a reference that gives the relevant numbers for the various
    >>>> editions of Windows. And second, could someone suggest a regex to parse
    >>>> it into consituent parts? Or, alternately, does someone have a better
    >>>> location to get the version and edition of Windows?
    >>>>
    >>>> Thanks,
    >>>>
    >>>> --
    >>>> Charlie.
    >>>> http://msmvps.com/xperts64
    >>>> http://mvp.support.microsoft.com/profile/charlie.russel
    >>>>
    >>>>
    >>>
    >>
    >

      My System SpecsSystem Spec

Page 1 of 3 123 LastLast
Reliable way to get Windows Version?

Similar Threads
Thread Thread Starter Forum Replies Last Post
New Share not reliable DHK Vista networking & sharing 5 15 Jun 2009
A reliable SENDKEYS for vb 2005 using Windows API Steve WinFX General 0 10 Jan 2008
Reliable OS? Vista General 17 07 Oct 2007
Just how reliable is Windows Easy Transfer? Qu0ll Vista General 6 27 Jun 2007
Reliable Messaging Ido Samuelson Indigo 1 04 Mar 2006