Repository: microsoft/CSS-Exchange
File: Diagnostics/HealthChecker/DataCollection/ServerInformation/Get-ServerOperatingSystemVersion.ps1 (PowerShell)

Code before:
        [string]$ComputerName = $env:COMPUTERNAME,

        [ScriptBlock]$CatchActionFunction
    )
    begin {
        Write-Verbose "Calling: $($MyInvocation.MyCommand)"
        $osReturnValue = [string]::Empty
    }
    process {
        Write-Verbose "Getting the version build information for computer: $ComputerName"
        $baseParams = @{
            MachineName         = $ComputerName
            CatchActionFunction = $CatchActionFunction
        }

        # Get ProductName via registry call as this is more accurate when running on Server Core
        $productNameParams = $baseParams + @{
            SubKey   = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
            GetValue = "ProductName"
        }

        # Find out if we're running on Server Core to output on the 'Operating System Information' page
        $installationTypeParams = $baseParams + @{
            SubKey   = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
            GetValue = "InstallationType"
        }

        $osCaption = Get-RemoteRegistryValue @productNameParams
        $installationType = Get-RemoteRegistryValue @installationTypeParams
        Write-Verbose "OsCaption: '$osCaption' InstallationType: '$installationType'"

        switch -Wildcard ($osCaption) {
            "*Server 2008 R2*" { $osReturnValue = "Windows2008R2"; break }
            "*Server 2008*" { $osReturnValue = "Windows2008" }
            "*Server 2012 R2*" { $osReturnValue = "Windows2012R2"; break }
            "*Server 2012*" { $osReturnValue = "Windows2012" }
            "*Server 2016*" { $osReturnValue = "Windows2016" }
            "*Server 2019*" { $osReturnValue = "Windows2019" }
            "*Server 2022*" { $osReturnValue = "Windows2022" }
            default { $osReturnValue = "Unknown" }
        }
    }
    end {
        Write-Verbose "OsReturnValue: '$osReturnValue'"
        return [PSCustomObject]@{
            MajorVersion     = $osReturnValue
            InstallationType = $installationType
            FriendlyName     = if ($installationType -eq "Server Core") { "$osCaption ($installationType)" } else { $osCaption }
        }
    }
}

Review comment (suggestion):
Doesn't matter to much, but for variables like this that aren't going to change, look better in `begin` block so that doesn't look so empty. Not a required change, just for future reference. 

Code after:
        [string]$ComputerName = $env:COMPUTERNAME,

        [ScriptBlock]$CatchActionFunction
    )
    begin {
        Write-Verbose "Calling: $($MyInvocation.MyCommand)"
        $osReturnValue = [string]::Empty
        $baseParams = @{
            MachineName         = $ComputerName
            CatchActionFunction = $CatchActionFunction
        }

        # Get ProductName via registry call as this is more accurate when running on Server Core
        $productNameParams = $baseParams + @{
            SubKey   = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
            GetValue = "ProductName"
        }

        # Find out if we're running on Server Core to output on the 'Operating System Information' page
        $installationTypeParams = $baseParams + @{
            SubKey   = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
            GetValue = "InstallationType"
        }
    }
    process {
        Write-Verbose "Getting the version build information for computer: $ComputerName"
        $osCaption = Get-RemoteRegistryValue @productNameParams
        $installationType = Get-RemoteRegistryValue @installationTypeParams
        Write-Verbose "OsCaption: '$osCaption' InstallationType: '$installationType'"

        switch -Wildcard ($osCaption) {
            "*Server 2008 R2*" { $osReturnValue = "Windows2008R2"; break }
            "*Server 2008*" { $osReturnValue = "Windows2008" }
            "*Server 2012 R2*" { $osReturnValue = "Windows2012R2"; break }
            "*Server 2012*" { $osReturnValue = "Windows2012" }
            "*Server 2016*" { $osReturnValue = "Windows2016" }
            "*Server 2019*" { $osReturnValue = "Windows2019" }
            "*Server 2022*" { $osReturnValue = "Windows2022" }
            default { $osReturnValue = "Unknown" }
        }
    }
    end {
        Write-Verbose "OsReturnValue: '$osReturnValue'"
        return [PSCustomObject]@{
            MajorVersion     = $osReturnValue
            InstallationType = $installationType
            FriendlyName     = if ($installationType -eq "Server Core") { "$osCaption ($installationType)" } else { $osCaption }
        }
    }
}