powershellvbscriptwmiwmi-query

VBScript OS Prop


I´m creating a VBScript to get OS information (to workstations and servers), At this point I need a function that gives me the OS Edition ONLY, example

WScript.Echo "Operating System Edition: "  Standard
WScript.Echo "Operating System Edition: "  Enterprise
WScript.Echo "Operating System Edition: "  Web
WScript.Echo "Operating System Edition: "  Pro
WScript.Echo "Operating System Edition: "  Ultimate

and so on...

I try to get this information using the WMI Class Win32_OperatingSystem, but no property available that shows this information.

Any Ideas?


Solution

  • There's a int-property called OpertingSystemSKU in Win32_OperatingSystem. You would have to convert that int into OS edition. An updated list of the values can be found at GetProductInfo @ MSDN.

    Here's a convert-function. I just used the constant-names so you might want to clean it up:

    function Get-OSSKU ([int]$int) {
    
        $SKU = @{
            0x00000006 = 'PRODUCT_BUSINESS'
            0x00000010 = 'PRODUCT_BUSINESS_N'
            0x00000012 = 'PRODUCT_CLUSTER_SERVER'
            0x00000040 = 'PRODUCT_CLUSTER_SERVER_V'
            0x00000065 = 'PRODUCT_CORE'
            0x00000063 = 'PRODUCT_CORE_COUNTRYSPECIFIC'
            0x00000062 = 'PRODUCT_CORE_N'
            0x00000064 = 'PRODUCT_CORE_SINGLELANGUAGE'
            0x00000050 = 'PRODUCT_DATACENTER_EVALUATION_SERVER'
            0x00000008 = 'PRODUCT_DATACENTER_SERVER'
            0x0000000C = 'PRODUCT_DATACENTER_SERVER_CORE'
            0x00000027 = 'PRODUCT_DATACENTER_SERVER_CORE_V'
            0x00000025 = 'PRODUCT_DATACENTER_SERVER_V'
            0x00000079 = 'PRODUCT_EDUCATION'
            0x0000007A = 'PRODUCT_EDUCATION_N'
            0x00000004 = 'PRODUCT_ENTERPRISE'
            0x00000046 = 'PRODUCT_ENTERPRISE_E'
            0x00000048 = 'PRODUCT_ENTERPRISE_EVALUATION'
            0x0000001B = 'PRODUCT_ENTERPRISE_N'
            0x00000054 = 'PRODUCT_ENTERPRISE_N_EVALUATION'
            0x0000007D = 'PRODUCT_ENTERPRISE_S'
            0x00000081 = 'PRODUCT_ENTERPRISE_S_EVALUATION'
            0x0000007E = 'PRODUCT_ENTERPRISE_S_N'
            0x00000082 = 'PRODUCT_ENTERPRISE_S_N_EVALUATION'
            0x0000000A = 'PRODUCT_ENTERPRISE_SERVER'
            0x0000000E = 'PRODUCT_ENTERPRISE_SERVER_CORE'
            0x00000029 = 'PRODUCT_ENTERPRISE_SERVER_CORE_V'
            0x0000000F = 'PRODUCT_ENTERPRISE_SERVER_IA64'
            0x00000026 = 'PRODUCT_ENTERPRISE_SERVER_V'
            0x0000003C = 'PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL'
            0x0000003E = 'PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC'
            0x0000003B = 'PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT'
            0x0000003D = 'PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC'
            0x00000002 = 'PRODUCT_HOME_BASIC'
            0x00000043 = 'PRODUCT_HOME_BASIC_E'
            0x00000005 = 'PRODUCT_HOME_BASIC_N'
            0x00000003 = 'PRODUCT_HOME_PREMIUM'
            0x00000044 = 'PRODUCT_HOME_PREMIUM_E'
            0x0000001A = 'PRODUCT_HOME_PREMIUM_N'
            0x00000022 = 'PRODUCT_HOME_PREMIUM_SERVER'
            0x00000013 = 'PRODUCT_HOME_SERVER'
            0x0000002A = 'PRODUCT_HYPERV'
            0x0000007B = 'PRODUCT_IOTUAP'
            0x00000083 = 'PRODUCT_IOTUAPCOMMERCIAL'
            0x0000001E = 'PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT'
            0x00000020 = 'PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING'
            0x0000001F = 'PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY'
            0x00000068 = 'PRODUCT_MOBILE_CORE'
            0x00000085 = 'PRODUCT_MOBILE_ENTERPRISE'
            0x0000004D = 'PRODUCT_MULTIPOINT_PREMIUM_SERVER'
            0x0000004C = 'PRODUCT_MULTIPOINT_STANDARD_SERVER'
            0x00000030 = 'PRODUCT_PROFESSIONAL'
            0x00000045 = 'PRODUCT_PROFESSIONAL_E'
            0x00000031 = 'PRODUCT_PROFESSIONAL_N'
            0x00000067 = 'PRODUCT_PROFESSIONAL_WMC'
            0x00000032 = 'PRODUCT_SB_SOLUTION_SERVER'
            0x00000036 = 'PRODUCT_SB_SOLUTION_SERVER_EM'
            0x00000033 = 'PRODUCT_SERVER_FOR_SB_SOLUTIONS'
            0x00000037 = 'PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM'
            0x00000018 = 'PRODUCT_SERVER_FOR_SMALLBUSINESS'
            0x00000023 = 'PRODUCT_SERVER_FOR_SMALLBUSINESS_V'
            0x00000021 = 'PRODUCT_SERVER_FOUNDATION'
            0x00000009 = 'PRODUCT_SMALLBUSINESS_SERVER'
            0x00000019 = 'PRODUCT_SMALLBUSINESS_SERVER_PREMIUM'
            0x0000003F = 'PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE'
            0x00000038 = 'PRODUCT_SOLUTION_EMBEDDEDSERVER'
            0x0000004F = 'PRODUCT_STANDARD_EVALUATION_SERVER'
            0x00000007 = 'PRODUCT_STANDARD_SERVER'
            0x0000000D = 'PRODUCT_STANDARD_SERVER_CORE'
            0x00000028 = 'PRODUCT_STANDARD_SERVER_CORE_V'
            0x00000024 = 'PRODUCT_STANDARD_SERVER_V'
            0x00000034 = 'PRODUCT_STANDARD_SERVER_SOLUTIONS'
            0x00000035 = 'PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE'
            0x0000000B = 'PRODUCT_STARTER'
            0x00000042 = 'PRODUCT_STARTER_E'
            0x0000002F = 'PRODUCT_STARTER_N'
            0x00000017 = 'PRODUCT_STORAGE_ENTERPRISE_SERVER'
            0x0000002E = 'PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE'
            0x00000014 = 'PRODUCT_STORAGE_EXPRESS_SERVER'
            0x0000002B = 'PRODUCT_STORAGE_EXPRESS_SERVER_CORE'
            0x00000060 = 'PRODUCT_STORAGE_STANDARD_EVALUATION_SERVER'
            0x00000015 = 'PRODUCT_STORAGE_STANDARD_SERVER'
            0x0000002C = 'PRODUCT_STORAGE_STANDARD_SERVER_CORE'
            0x0000005F = 'PRODUCT_STORAGE_WORKGROUP_EVALUATION_SERVER'
            0x00000016 = 'PRODUCT_STORAGE_WORKGROUP_SERVER'
            0x0000002D = 'PRODUCT_STORAGE_WORKGROUP_SERVER_CORE'
            0x00000001 = 'PRODUCT_ULTIMATE'
            0x00000047 = 'PRODUCT_ULTIMATE_E'
            0x0000001C = 'PRODUCT_ULTIMATE_N'
            0x00000000 = 'PRODUCT_UNDEFINED'
            0x00000011 = 'PRODUCT_WEB_SERVER'
            0x0000001D = 'PRODUCT_WEB_SERVER_CORE'
        }
    
        $sku[$int]
    
    }
    

    Demo:

    $osSKU = Get-WmiObject Win32_OperatingSystem | Select-Object -ExpandProperty OperatingSystemSKU
    
    "Computer has SKU $osSKU which is '$(Get-OSSKU $osSKU)'"
    Computer has SKU 48 which is 'PRODUCT_PROFESSIONAL'
    

    UPDATE: How to use different solutions for different OSVersions:

    $os = Get-WmiObject Win32_OperatingSystem
    
    switch -Wildcard ($os.Version) {
        "5.*" {
            #2003 / 2003 R2
            $_.Caption.Split(",")[-1].Trim()
        }
        "6.*" {
            #2008+
            Get-OSSKU $os.OperatingSystemSKU
        }
        "10.*" {
            Get-OSSKU $os.OperatingSystemSKU
        }
        default { 
            #Fallback. Pre-2003 OS. Don't know how to handle
            $os.Caption
        }
    }