Skip to content

Instantly share code, notes, and snippets.

@MyITGuy
Last active November 1, 2023 19:07
Show Gist options
  • Save MyITGuy/024beaf64c0e461d1245 to your computer and use it in GitHub Desktop.
Save MyITGuy/024beaf64c0e461d1245 to your computer and use it in GitHub Desktop.
PowerShell: Get the operating system product type.
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 {
}
}
@TonaIslas-Git
Copy link

Thanks. I will use it and modify it. I will leave the original creator at the top with ref to this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment