Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Reliable way to get Windows Version?

Reply
 
Old 03-22-2008   #21 (permalink)
Charlie Russel - MVP


 
 

Re: Reliable way to get Windows Version?

Yeah, I knew I was letting myself in for it.

The only problem I had with the WMI calls was that I wanted to get them into
a hash. And I couldn't figure an easy way to get there from here, so I just
did it the hard way, knowing it was wrong (well, OK, not wrong, but
"inefficient").

I actually had OSArchitecture in there for the 32/64 bit, but since none of
this has to run remotely, _yet_, I went with the simpler ENV: variable,
since it was already there.

Nice touch on the break - I'd forgotten that behaviour. I'm more used to
case statements where the first match breaks out of it.

Thanks, I learn far more by doing and posting my mistakes for others to
(gently) abuse, than by reading any number of books.

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


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

>
> Hi
>
> Crude indeed too many WMI calls on the same class. You can get all
> properties in one WMI call. To change coulmn names you can
> use calculated properites. Bear in mind that OperatingSystemSKU is not
> available on Windows Server 2003, Windows XP, Windows 2000, and Windows NT
> 4.0.
> One more thing, $arch is not usefull in case of remote wmi calls:
>
>
> $build = @{n="Build";e={$_.BuildNumber}}
> $SPNumber = @{n="SPNumber";e={$_.CSDVersion}}
> $sku = @{n="SKU";e={$_.OperatingSystemSKU}}
> $hostname = @{n="HostName";e={$_.CSName}}
> $arch = $ENV:Processor_Architecture
>
> $os = Get-WmiObject Win32_OperatingSystem | select
> $build,$SPNumber,Caption,$sku,$hostname
>
>
> ## If you want the switch statement to stop at the ## first match than add
> the break statement
>
> switch ($os.build) {
> 2600 {"XP"; break}
> 3790 { if ($os.caption -match "XP") { "XPx64" } else { "Server 2003" };
> break }
> 6000 {"Vista"; break}
> 6001 { if ($os.caption -match "Vista" ) { "Vista" } else { "Server
> 2008" }; break }
> }
>
>
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> Fairly crude at this point, and I'm not finished doing what I need to
>> do with it, but here's the relevant portion for the moment:
>>
>> $SystemHash = @{} # Initialize the variable as a hashtable
>> $SystemHash["build"] = (Get-WmiObject
>> Win32_OperatingSystem).BuildNumber
>> $SystemHash["SPNumber"] = (Get-WmiObject
>> Win32_OperatingSystem).CSDVersion
>> $SystemHash["Caption"] = (Get-WmiObject Win32_OperatingSystem).Caption
>> $SystemHash["SKU"] = (Get-WmiObject
>> Win32_OperatingSystem).OperatingSystemSKU
>> $SystemHash["Hostname"] = $hostname.ToLower()
>> $SystemHash["Arch"] = $ENV:Processor_Architecture
>> switch -regex ($SystemHash["Build"]) {
>> 2600 { $ver="XP" }
>> 3790 { if ($SystemHash["Caption"] -match "XP") {
>> $ver = "XPx64"
>> } else {
>> $ver = "Server 2003"
>> }
>> }
>> 6000 { $ver="Vista" }
>> 6001 { if ($SystemHash["Caption"] -match "Vista" ) {
>> $ver="Vista"
>> } else {
>> $ver="Server 2008"
>> }
>> }
>> }
>> "Hal Rottenberg" <hal@xxxxxx> wrote in message
>> news:uyMQEOoiIHA.4320@xxxxxx
>>
Quote:

>>> Charlie Russel - MVP wrote:
>>>
>>>> Thanks, Jon, Shay, Hal and Andy. Very much appreciated. I've got a
>>>> couple of ways to do what I need to do, based on what you gave me.
>>>> For the moment, I'm going with a combination of
>>>> Win32_OperatingSystem properties, including BuildNumber, Caption,
>>>> CSDVersion and operatingsystemSKU.
>>>>
>>> YW. If you can, please report back with your code as a lesson for
>>> others.
>>>
>>> --
>>>
>>> Hal Rottenberg
>>> Blog: http://halr9000.com
>>> Webmaster, Psi (http://psi-im.org)
>>> Co-host, PowerScripting Podcast (http://powerscripting.net)
>
>

My System SpecsSystem Spec
Old 03-23-2008   #22 (permalink)
Shay Levi


 
 

Re: Reliable way to get Windows Version?


That's OK, it's a part of the learning curve, nobody is mistake proof ;-),
keep posting.

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

> Yeah, I knew I was letting myself in for it.
>
> The only problem I had with the WMI calls was that I wanted to get
> them into a hash. And I couldn't figure an easy way to get there from
> here, so I just did it the hard way, knowing it was wrong (well, OK,
> not wrong, but "inefficient").
>
> I actually had OSArchitecture in there for the 32/64 bit, but since
> none of this has to run remotely, _yet_, I went with the simpler ENV:
> variable, since it was already there.
>
> Nice touch on the break - I'd forgotten that behaviour. I'm more used
> to case statements where the first match breaks out of it.
>
> Thanks, I learn far more by doing and posting my mistakes for others
> to (gently) abuse, than by reading any number of books.
>
> "Shay Levi" <no@xxxxxx> wrote in message
> news:8766a94424a588ca5a94dc3386c0@xxxxxx
>
Quote:

>> Hi
>>
>> Crude indeed too many WMI calls on the same class. You can get all
>> properties in one WMI call. To change coulmn names you can
>> use calculated properites. Bear in mind that OperatingSystemSKU is
>> not
>> available on Windows Server 2003, Windows XP, Windows 2000, and
>> Windows NT
>> 4.0.
>> One more thing, $arch is not usefull in case of remote wmi calls:
>> $build = @{n="Build";e={$_.BuildNumber}}
>> $SPNumber = @{n="SPNumber";e={$_.CSDVersion}}
>> $sku = @{n="SKU";e={$_.OperatingSystemSKU}}
>> $hostname = @{n="HostName";e={$_.CSName}}
>> $arch = $ENV:Processor_Architecture
>> $os = Get-WmiObject Win32_OperatingSystem | select
>> $build,$SPNumber,Caption,$sku,$hostname
>>
>> ## If you want the switch statement to stop at the ## first match
>> than add the break statement
>>
>> switch ($os.build) {
>> 2600 {"XP"; break}
>> 3790 { if ($os.caption -match "XP") { "XPx64" } else { "Server 2003"
>> };
>> break }
>> 6000 {"Vista"; break}
>> 6001 { if ($os.caption -match "Vista" ) { "Vista" } else { "Server
>> 2008" }; break }
>> }
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
Quote:

>>> Fairly crude at this point, and I'm not finished doing what I need
>>> to do with it, but here's the relevant portion for the moment:
>>>
>>> $SystemHash = @{} # Initialize the variable as a hashtable
>>> $SystemHash["build"] = (Get-WmiObject
>>> Win32_OperatingSystem).BuildNumber
>>> $SystemHash["SPNumber"] = (Get-WmiObject
>>> Win32_OperatingSystem).CSDVersion
>>> $SystemHash["Caption"] = (Get-WmiObject
>>> Win32_OperatingSystem).Caption
>>> $SystemHash["SKU"] = (Get-WmiObject
>>> Win32_OperatingSystem).OperatingSystemSKU
>>> $SystemHash["Hostname"] = $hostname.ToLower()
>>> $SystemHash["Arch"] = $ENV:Processor_Architecture
>>> switch -regex ($SystemHash["Build"]) {
>>> 2600 { $ver="XP" }
>>> 3790 { if ($SystemHash["Caption"] -match "XP") {
>>> $ver = "XPx64"
>>> } else {
>>> $ver = "Server 2003"
>>> }
>>> }
>>> 6000 { $ver="Vista" }
>>> 6001 { if ($SystemHash["Caption"] -match "Vista" ) {
>>> $ver="Vista"
>>> } else {
>>> $ver="Server 2008"
>>> }
>>> }
>>> }
>>> "Hal Rottenberg" <hal@xxxxxx> wrote in message
>>> news:uyMQEOoiIHA.4320@xxxxxx
>>>> Charlie Russel - MVP wrote:
>>>>
>>>>> Thanks, Jon, Shay, Hal and Andy. Very much appreciated. I've got a
>>>>> couple of ways to do what I need to do, based on what you gave me.
>>>>> For the moment, I'm going with a combination of
>>>>> Win32_OperatingSystem properties, including BuildNumber, Caption,
>>>>> CSDVersion and operatingsystemSKU.
>>>>>
>>>> YW. If you can, please report back with your code as a lesson for
>>>> others.
>>>>
>>>> --
>>>>
>>>> Hal Rottenberg
>>>> Blog: http://halr9000.com
>>>> Webmaster, Psi (http://psi-im.org)
>>>> Co-host, PowerScripting Podcast (http://powerscripting.net)

My System SpecsSystem Spec
Old 03-23-2008   #23 (permalink)
Charlie Russel - MVP


 
 

Re: Reliable way to get Windows Version?

Yup, it's all part of the learning process.

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


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

>
> That's OK, it's a part of the learning curve, nobody is mistake proof ;-),
> keep posting.
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> Yeah, I knew I was letting myself in for it.
>>
>> The only problem I had with the WMI calls was that I wanted to get
>> them into a hash. And I couldn't figure an easy way to get there from
>> here, so I just did it the hard way, knowing it was wrong (well, OK,
>> not wrong, but "inefficient").
>>
>> I actually had OSArchitecture in there for the 32/64 bit, but since
>> none of this has to run remotely, _yet_, I went with the simpler ENV:
>> variable, since it was already there.
>>
>> Nice touch on the break - I'd forgotten that behaviour. I'm more used
>> to case statements where the first match breaks out of it.
>>
>> Thanks, I learn far more by doing and posting my mistakes for others
>> to (gently) abuse, than by reading any number of books.
>>
>> "Shay Levi" <no@xxxxxx> wrote in message
>> news:8766a94424a588ca5a94dc3386c0@xxxxxx
>>
Quote:

>>> Hi
>>>
>>> Crude indeed too many WMI calls on the same class. You can get all
>>> properties in one WMI call. To change coulmn names you can
>>> use calculated properites. Bear in mind that OperatingSystemSKU is
>>> not
>>> available on Windows Server 2003, Windows XP, Windows 2000, and
>>> Windows NT
>>> 4.0.
>>> One more thing, $arch is not usefull in case of remote wmi calls:
>>> $build = @{n="Build";e={$_.BuildNumber}}
>>> $SPNumber = @{n="SPNumber";e={$_.CSDVersion}}
>>> $sku = @{n="SKU";e={$_.OperatingSystemSKU}}
>>> $hostname = @{n="HostName";e={$_.CSName}}
>>> $arch = $ENV:Processor_Architecture
>>> $os = Get-WmiObject Win32_OperatingSystem | select
>>> $build,$SPNumber,Caption,$sku,$hostname
>>>
>>> ## If you want the switch statement to stop at the ## first match
>>> than add the break statement
>>>
>>> switch ($os.build) {
>>> 2600 {"XP"; break}
>>> 3790 { if ($os.caption -match "XP") { "XPx64" } else { "Server 2003"
>>> };
>>> break }
>>> 6000 {"Vista"; break}
>>> 6001 { if ($os.caption -match "Vista" ) { "Vista" } else { "Server
>>> 2008" }; break }
>>> }
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> Fairly crude at this point, and I'm not finished doing what I need
>>>> to do with it, but here's the relevant portion for the moment:
>>>>
>>>> $SystemHash = @{} # Initialize the variable as a hashtable
>>>> $SystemHash["build"] = (Get-WmiObject
>>>> Win32_OperatingSystem).BuildNumber
>>>> $SystemHash["SPNumber"] = (Get-WmiObject
>>>> Win32_OperatingSystem).CSDVersion
>>>> $SystemHash["Caption"] = (Get-WmiObject
>>>> Win32_OperatingSystem).Caption
>>>> $SystemHash["SKU"] = (Get-WmiObject
>>>> Win32_OperatingSystem).OperatingSystemSKU
>>>> $SystemHash["Hostname"] = $hostname.ToLower()
>>>> $SystemHash["Arch"] = $ENV:Processor_Architecture
>>>> switch -regex ($SystemHash["Build"]) {
>>>> 2600 { $ver="XP" }
>>>> 3790 { if ($SystemHash["Caption"] -match "XP") {
>>>> $ver = "XPx64"
>>>> } else {
>>>> $ver = "Server 2003"
>>>> }
>>>> }
>>>> 6000 { $ver="Vista" }
>>>> 6001 { if ($SystemHash["Caption"] -match "Vista" ) {
>>>> $ver="Vista"
>>>> } else {
>>>> $ver="Server 2008"
>>>> }
>>>> }
>>>> }
>>>> "Hal Rottenberg" <hal@xxxxxx> wrote in message
>>>> news:uyMQEOoiIHA.4320@xxxxxx
>>>>> Charlie Russel - MVP wrote:
>>>>>
>>>>>> Thanks, Jon, Shay, Hal and Andy. Very much appreciated. I've got a
>>>>>> couple of ways to do what I need to do, based on what you gave me.
>>>>>> For the moment, I'm going with a combination of
>>>>>> Win32_OperatingSystem properties, including BuildNumber, Caption,
>>>>>> CSDVersion and operatingsystemSKU.
>>>>>>
>>>>> YW. If you can, please report back with your code as a lesson for
>>>>> others.
>>>>>
>>>>> --
>>>>>
>>>>> Hal Rottenberg
>>>>> Blog: http://halr9000.com
>>>>> Webmaster, Psi (http://psi-im.org)
>>>>> Co-host, PowerScripting Podcast (http://powerscripting.net)
>
>
My System SpecsSystem Spec
Old 03-27-2008   #24 (permalink)
Hal Rottenberg


 
 

Re: Reliable way to get Windows Version?

Charlie Russel - MVP wrote:
Quote:

> The only problem I had with the WMI calls was that I wanted to get them
> into a hash. And I couldn't figure an easy way to get there from here,
Check it out:

88# $a = gwmi Win32_OperatingSystem
89# $SystemHash = @{}
90# $systemhash.build, $systemhash.SPNumber, $systemhash.Caption = `
$a.BuildNumber, $a.CSDVersion, $a.Caption

91# $systemhash

Name Value
---- -----
build 2600
Caption Microsoft Windows XP Professional
SPNumber Service Pack 2

But really, in this case I don't see the need for a hashtable at all,
considering that $a here is a perfectly usable collection already. Just wanted
to provide the examples of "property-style" addressing of hashtable keys and
multiple variable assignment features which are pretty darn cool if you ask me.

--

Hal Rottenberg
Blog: http://halr9000.com
Webmaster, Psi (http://psi-im.org)
Co-host, PowerScripting Podcast (http://powerscripting.net)
My System SpecsSystem Spec
Old 03-28-2008   #25 (permalink)
Charlie Russel - MVP


 
 

Re: Reliable way to get Windows Version?

hunh. Now see, I didn't know I could do it that way (multiple assignments on
each side of the equation.) You're right. That's cool.

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


"Hal Rottenberg" <hal@xxxxxx> wrote in message
news:ecJ1SQEkIHA.5820@xxxxxx
Quote:

> Charlie Russel - MVP wrote:
Quote:

>> The only problem I had with the WMI calls was that I wanted to get them
>> into a hash. And I couldn't figure an easy way to get there from here,
>
> Check it out:
>
> 88# $a = gwmi Win32_OperatingSystem
> 89# $SystemHash = @{}
> 90# $systemhash.build, $systemhash.SPNumber, $systemhash.Caption = `
> $a.BuildNumber, $a.CSDVersion, $a.Caption
>
> 91# $systemhash
>
> Name Value
> ---- -----
> build 2600
> Caption Microsoft Windows XP Professional
> SPNumber Service Pack 2
>
> But really, in this case I don't see the need for a hashtable at all,
> considering that $a here is a perfectly usable collection already. Just
> wanted to provide the examples of "property-style" addressing of hashtable
> keys and multiple variable assignment features which are pretty darn cool
> if you ask me.
>
> --
>
> Hal Rottenberg
> Blog: http://halr9000.com
> Webmaster, Psi (http://psi-im.org)
> Co-host, PowerScripting Podcast (http://powerscripting.net)
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Reliable OS? Vista General
Just how reliable is Windows Easy Transfer? Vista General
most reliable newsreader Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46