When working with Windows Server 2016 Nano Server, you'll quickly discover that many traditional version-checking methods don't work. The stripped-down nature of Nano Server means:
- Full .NET Framework is unavailable
- Get-WmiObject cmdlet is missing
- Many standard PowerShell commands return limited information
Here are the working approaches I've found for determining the Nano Server version:
1. Using DISM Tool
The Deployment Image Servicing and Management tool provides some version information:
Dism /Online /Get-Feature
Sample output:
Deployment Image Servicing and Management tool
Version: 10.0.10514.0
Image Version: 10.0.10514.0
2. Registry Query Method
A more reliable approach is querying the registry:
Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion' |
Select-Object ProductName, ReleaseId, CurrentBuild
3. Environment Class (Limited Info)
While this only shows kernel version, it can be useful:
[System.Environment]::OSVersion.Version
Here's a PowerShell function that combines multiple approaches:
function Get-NanoServerVersion {
try {
$reg = Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion'
$osVersion = [System.Environment]::OSVersion.Version
[PSCustomObject]@{
ProductName = $reg.ProductName
ReleaseId = $reg.ReleaseId
CurrentBuild = $reg.CurrentBuild
KernelVersion = $osVersion.ToString()
IsNanoServer = ($reg.InstallationType -eq 'NanoServer')
}
}
catch {
try {
$dismOutput = Dism /Online /Get-Feature
$versionLine = $dismOutput | Where-Object { $_ -match 'Version:\s\d+\.\d+\.\d+\.\d+' }
$version = $matches[0] -replace 'Version:\s',''
[PSCustomObject]@{
ProductName = 'Windows Server 2016 Nano'
KernelVersion = $version
IsNanoServer = $true
}
}
catch {
Write-Warning "Could not determine Nano Server version"
}
}
}
To detect if you're running on Nano Server:
if ((Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion').InstallationType -eq 'NanoServer') {
Write-Output "Running on Nano Server"
}
If CIM is available (though often not on Nano Server):
Get-CimInstance -ClassName Win32_OperatingSystem |
Select-Object Caption, Version, BuildNumber
For most reliable results:
- Use the registry method as primary approach
- Fall back to DISM if registry access fails
- Cache the version information if you need it frequently
- Consider adding version checks to your script's prerequisites validation
Windows Server 2016 Nano edition presents unique challenges for version detection due to its minimal footprint. Traditional methods like Get-WmiObject Win32_OperatingSystem
or full .NET framework calls aren't available in this constrained environment.
Here are the most reliable approaches I've found:
# Method 1: Using DISM (most reliable)
Dism /Online /Get-CurrentEdition
This returns output like:
Current edition is:
Edition ID: ServerStandardNano
# Method 2: Registry query
Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' |
Select-Object ProductName, ReleaseId, CurrentBuild
While [System.Environment]::OSVersion.Version
gives the kernel build (e.g., 10.0.10514), this doesn't indicate the Nano Server edition. The kernel version may match other Windows 10/Server 2016 variants.
Here's a robust function that combines multiple approaches:
function Get-NanoServerVersion {
$result = @{}
# Try registry first
try {
$reg = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$result.ProductName = $reg.ProductName
$result.EditionID = $reg.EditionID
$result.BuildNumber = $reg.CurrentBuild
}
catch { }
# Fallback to DISM if registry fails
if (-not $result.EditionID) {
try {
$dism = Dism /Online /Get-CurrentEdition
$result.EditionID = ($dism -match 'Edition ID: (.*)')[0] -replace 'Edition ID: ',''
}
catch { }
}
# Final fallback to kernel version
if (-not $result.BuildNumber) {
$result.BuildNumber = [System.Environment]::OSVersion.Version.Build
}
return [PSCustomObject]$result
}
The registry and DISM approaches are effective because:
- Nano Server maintains basic registry structure for version information
- DISM is a core component that survives the Nano Server trimming
- Both methods don't depend on WMI or full .NET framework