MyITGuy
8/6/2015 - 1:38 PM

PowerShell: Get the operating system product type.

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 {
	}
}