JRE-Modules.psm1
|
# JRE-Modules - Composite PowerShell Module # This module loads all nested submodules from the JRE-Modules collection Write-Verbose "Loading JRE-Modules composite module..." # Modules are automatically loaded via NestedModules in the manifest # No additional initialization needed at this time $module = $ExecutionContext.SessionState.Module $moduleName = $module.Name $currentVersion = [string]$module.Version $currentPrerelease = $null if ($module.PrivateData -and $module.PrivateData.PSData) { $currentPrerelease = [string]$module.PrivateData.PSData.Prerelease } $currentDisplayVersion = if ([string]::IsNullOrWhiteSpace($currentPrerelease)) { $currentVersion } else { "$currentVersion-$currentPrerelease" } $latestDisplayVersion = $null try { if (Get-Command -Name Find-PSResource -ErrorAction SilentlyContinue) { $latest = Find-PSResource -Name $moduleName -Repository PSGallery -ErrorAction Stop | Select-Object -First 1 if ($null -ne $latest) { $latestDisplayVersion = [string]$latest.Version } } elseif (Get-Command -Name Find-Module -ErrorAction SilentlyContinue) { $latest = Find-Module -Name $moduleName -Repository PSGallery -ErrorAction Stop if ($null -ne $latest) { $latestPrerelease = $null if ($latest.AdditionalMetadata -and $latest.AdditionalMetadata.ContainsKey('Prerelease')) { $latestPrerelease = [string]$latest.AdditionalMetadata['Prerelease'] } $latestDisplayVersion = if ([string]::IsNullOrWhiteSpace($latestPrerelease)) { [string]$latest.Version } else { "$($latest.Version)-$latestPrerelease" } } } } catch { $latestDisplayVersion = $null } $updateAvailable = $false if (-not [string]::IsNullOrWhiteSpace($latestDisplayVersion)) { try { $updateAvailable = ([System.Management.Automation.SemanticVersion]$latestDisplayVersion -gt [System.Management.Automation.SemanticVersion]$currentDisplayVersion) } catch { $updateAvailable = ($latestDisplayVersion -ne $currentDisplayVersion) } } Write-Host ("=" * 88) -ForegroundColor Cyan Write-Host "JRE-Modules imported. Run 'Get-Command -Module JRE-Modules' and 'Get-Help <CommandName> -Detailed' for detailed information on available commands." -ForegroundColor Green if ($updateAvailable) { Write-Host ("Update available: {0} -> {1}" -f $currentDisplayVersion, $latestDisplayVersion) -ForegroundColor Yellow Write-Host "Run 'Update-Module -Name $moduleName' to get the latest version." -ForegroundColor Yellow Write-Host "You will need to re-import the module with the '-Force' parameter after updating to load the new version." -ForegroundColor Yellow } Write-Host ("=" * 88) -ForegroundColor Cyan Write-Verbose "JRE-Modules composite module loaded successfully." |