Private/Test/Test-IsSupportedPS.ps1
|
function Test-IsSupportedPS { <# .SYNOPSIS Tests if the current PowerShell version is supported by Locksmith 2. .DESCRIPTION Checks if the PowerShell version meets the minimum requirements for Locksmith 2. Supported versions are: - Windows PowerShell 5.1 - PowerShell 7.4 or later This function validates both the major and minor version numbers to ensure compatibility with module features and dependencies. .INPUTS None. This function does not accept pipeline input. .OUTPUTS System.Boolean Returns $true if the PowerShell version is supported (5.1 or 7.4+). Returns $false for unsupported versions. .EXAMPLE Test-IsSupportedPS Returns $true if running PowerShell 5.1 or PowerShell 7.4+. .EXAMPLE if (-not (Test-IsSupportedPS)) { throw "Locksmith 2 requires PowerShell 5.1 or PowerShell 7.4 or later." } Throws an error if the PowerShell version is not supported. .EXAMPLE Test-IsSupportedPS -Verbose Tests PowerShell version and displays verbose output showing the detected version. .NOTES Supported PowerShell Versions: - Windows PowerShell 5.1 - PowerShell 7.4 or later PowerShell 6.x and 7.0-7.3 are not supported due to missing features or incompatibilities. .LINK https://learn.microsoft.com/en-us/powershell/scripting/install/powershell-support-lifecycle #> [CmdletBinding()] [OutputType([bool])] param ( ) #requires -Version 5.1 # Extract major and minor version numbers from $PSVersionTable $PSMajorVersion = $PSVersionTable.PSVersion.Major $PSMinorVersion = $PSVersionTable.PSVersion.Minor # Log the detected PowerShell version for troubleshooting Write-Verbose "PowerShell version: ${PSMajorVersion}.$PSMinorVersion" if ($PSMajorVersion -eq 5 -and $PSMinorVersion -eq 1) { # Check if running Windows PowerShell 5.1 $true } elseif ($PSMajorVersion -eq 7 -and $PSMinorVersion -ge 4) { # Check if running PowerShell 7.4 or later $true } else { # All other versions are unsupported $false } } |