PowerShell
PowerShell copied to clipboard
PSVersionTable should have Release type field denoting Prerelease, Stable, or LTS
Summary of the new feature / enhancement
$PSVersionTable should have a property (Release) field denoting if the version is Prerelease, Stable, or LTS.
Proposed technical implementation details (optional)
$PSVersionTable.Release = if ($PSVersionTable.PSVersion.PreReleaseLabel) {
'Prerelease'
} elseif ($PSVersionTable.PSVersion.Minor % 2 -eq 0) {
'LTS'
} else {
'Stable'
}
Related:
- #19121
$PSVersionTable.PSVersion.PreReleaseLabel
Why define the release status using PreReleasLabel property when $PSVersionTable.Release returns it?
$ $PSVersionTable.Release
Prerelease
@237dmitry, there is currently no $PSVersionTable.Release entry - except after running the code in the initial post (I don't know how easy it would be to enforce it, but conceptually, $PSVersionTable should be read-only).
@ThomasNieto, I like the idea, but I suggest the following tweaks:
- To lessen ambiguity and to align with existing key names, I suggest
PSReleaseTypeas the name. - Also support detecting custom builds, such as during development (I'm not sure if there's a better way to detect them than what I use below).
- Use an
enumtype for the values, for type safety in programmatic use.
Thus, something like the following:
enum PSReleaseType {
Stable = 0
LTS
Prerelease
Custom
}
$PSVersionTable.PSReleaseType =
if ($PSVersionTable.GitCommitId -like '*-*-*') { # There may be a better way to detect this
[PSReleaseType]::Custom
} elseif ($PSVersionTable.PSVersion.PreReleaseLabel) {
[PSReleaseType]::Prerelease
} elseif ($PSVersionTable.PSVersion.Minor % 2 -eq 0) {
[PSReleaseType]::LTS
} else {
[PSReleaseType]::Stable
}
there is currently no $PSVersionTable.Release entry - except after running the code in the initial post (I don't know how easy it would be to enforce it, but conceptually, $PSVersionTable should be read-only).
Yes, I actually ran the original code and then looked at the output of $PSVersionTable
I agree it should be read-only