"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