Last active
November 1, 2023 19:07
-
-
Save MyITGuy/024beaf64c0e461d1245 to your computer and use it in GitHub Desktop.
PowerShell: Get the operating system product type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-OSProductType { | |
[CmdletBinding(SupportsShouldProcess=$True,DefaultParameterSetName="None")] | |
PARAM( | |
[Parameter(Mandatory = $false, Position = 0, ValueFromPipeline = $true)] | |
[string]$ComputerName = $env:COMPUTERNAME | |
) | |
<# | |
.SYNOPSIS | |
Get the operating system product type. | |
.DESCRIPTION | |
Use to get the product type of the operating system. The return will be Workstation, Server, Domain Controller or Unknown. | |
.NOTES | |
2015-08-06 Version 1.0 | |
#> | |
BEGIN { | |
} | |
PROCESS { | |
try { | |
$wmiOperatingSystem = Get-CimInstance -ComputerName $ComputerName -ClassName Win32_OperatingSystem | Where {$_.Primary -eq $true} | |
} catch {} | |
if ($wmiOperatingSystem) { | |
switch($wmiOperatingSystem.ProductType) { | |
1 {"Workstation"} | |
2 {"Domain Controller"} | |
3 {"Server"} | |
default {"Unknown"} | |
} | |
} | |
} | |
END { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. I will use it and modify it. I will leave the original creator at the top with ref to this repo.