11function Get-ModuleExtension {
2+ <#
3+ . SYNOPSIS
4+ Retrieves module extensions based on specified criteria.
5+
6+ . DESCRIPTION
7+ This function retrieves module extensions that match the specified module
8+ name and version criteria.
9+
10+ . PARAMETER ModuleName
11+ The name of the module to retrieve extensions for.
12+
13+ . PARAMETER ModuleVersion
14+ The version of the module to retrieve extensions for.
15+
16+ . PARAMETER ListAvailable
17+ Indicates whether to list all available modules or only the the latest
18+ version of each module.
19+
20+ . EXAMPLE
21+ Get-ModuleExtension -ModuleName "MyModule" -ModuleVersion "1.0.0"
22+
23+ Retrieves extensions for the module "MyModule" with version "1.0.0".
24+ . NOTES
25+
26+ #>
227 [CmdletBinding ()]
328 param (
429 [string ]
@@ -11,9 +36,9 @@ function Get-ModuleExtension {
1136 $ListAvailable
1237 )
1338
14- # Only get the latest version of each module
39+ # Only get the latest version of each module
1540 $modules = Get-Module - ListAvailable
16- if (! $ListAvailable ) {
41+ if (! $ListAvailable.IsPresent ) {
1742 $modules = $modules |
1843 Group-Object Name |
1944 ForEach-Object {
@@ -25,28 +50,6 @@ function Get-ModuleExtension {
2550
2651 Write-Verbose " Found $ ( $modules.Length ) installed modules to scan for extensions."
2752
28- function ParseVersion ($versionString ) {
29- $parsedVersion = $null
30-
31- if ($versionString ) {
32- # We're targeting Semantic Versioning 2.0 so make sure the version has
33- # at least 3 components (X.X.X). This logic ensures that the "patch"
34- # (third) component has been specified.
35- $versionParts = $versionString.Split (' .' )
36- if ($versionParts.Length -lt 3 ) {
37- $versionString = " $versionString .0"
38- }
39-
40- if ($PSVersionTable.PSEdition -eq " Core" ) {
41- $parsedVersion = New-Object - TypeName " System.Management.Automation.SemanticVersion" - ArgumentList $versionString
42- } else {
43- $parsedVersion = New-Object - TypeName " System.Version" - ArgumentList $versionString
44- }
45- }
46-
47- return $parsedVersion
48- }
49-
5053 foreach ($module in $modules ) {
5154 if ($module.PrivateData -and
5255 $module.PrivateData.PSData -and
@@ -58,8 +61,18 @@ function Get-ModuleExtension {
5861
5962 Write-Verbose " Comparing against module extension: $ ( $extension.Module ) "
6063
61- $minimumVersion = ParseVersion $extension.MinimumVersion
62- $maximumVersion = ParseVersion $extension.MaximumVersion
64+ if ([String ]::IsNullOrEmpty($extension.MinimumVersion )) {
65+ # Fill with a default value if not specified
66+ $minimumVersion = $null
67+ } else {
68+ $minimumVersion = Resolve-ModuleVersionString $extension.MinimumVersion
69+ }
70+ if ([String ]::IsNullOrEmpty($extension.MaximumVersion )) {
71+ # Fill with a default value if not specified
72+ $maximumVersion = $null
73+ } else {
74+ $maximumVersion = Resolve-ModuleVersionString $extension.MaximumVersion
75+ }
6376
6477 if (($extension.Module -eq $ModuleName ) -and
6578 (! $minimumVersion -or $ModuleVersion -ge $minimumVersion ) -and
0 commit comments