Public/Get-WindowsVersion.ps1

function Get-WindowsVersion
{
    <#
        .DESCRIPTION
            Check if a device is running Windows 10 or Windows 11
    
        .EXAMPLE
            $WindowsVersion = Get-WindowsVersion
    
        .NOTES
            Created by: Jon Anderson
            Modified: 2023-07-03
    #>

    $Caption = Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty Caption
    switch($Caption)
    {
        {$_ -match "Microsoft Windows 10"} {return "Windows 10"}
        {$_ -match "Microsoft Windows 11"} {return "Windows 11"}
        Default {return "Invalid OS"}
    }
}