Can you distinguish between Windows 7 and Windows Server 2008 R2?

My precedent is for what I need: the goal I want to achieve is the ability to silently deploy PowerShell 5 only on workstations through automation, I should be able to prevent my deployment from deploying from servers so that I don't force the world to spontaneously collapse itself by oneself.

I am currently using the following code to capture a powered version of a shell

$BuildVersion = [System.Environment]::OSVersion.Version
Write-Host($BuildVersion)

and using

if ($BuildVersion.Major -le '6')

To exclude any machines that are not running at least 7, I found that I would have a problem since Windows 7 and Windows Server 2008 R2 have the same major build number.

My first thought was to change the code to only allow specific build numbers

, 7 2008 R2 6.1.7601.

, PowerShell 2.0 Windows, .

, .

+4
1

Win32_OperatingSystem . ProductType. 1 , (.. Windows 7), 2 3 ( Windows Server 2008 R2).

[System.Version] , Major Minor ($BuildVersion.Major -eq 6 Vista, 7)

# Define a minimum version (Win7 family pre-release build)
$MinimumVersion = [version]'6.1'

# Fetch ProductType from WMI
$OSType = (Get-WmiObject -Class Win32_OperatingSystem -Property ProductType).ProductType

if($OSType -eq 1 -and [Environment]::Version -ge $MinimumVersion){
    # client OS, 7 or newer
}
+3

Source: https://habr.com/ru/post/1668681/


All Articles