Skip to content

Commit 0075a98

Browse files
authored
Merge pull request #37 from tpcarman/dev
Fix Get-RequiredModule function
2 parents ffa99cb + 4ffde8b commit 0075a98

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

AsBuiltReport.VMware.Horizon.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'AsBuiltReport.VMware.Horizon.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.1.5'
15+
ModuleVersion = '1.1.5.1'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [1.1.5] - 2025-1-21
8+
## [1.1.5.1] - 2025-03-13
9+
10+
### Fixed
11+
- Fix `Get-RequiredModule` script function to properly check for installed VMware PowerCLI versions ([Fix #36](https://github.com/AsBuiltReport/AsBuiltReport.VMware.Horizon/issues/36))
12+
13+
## [1.1.5] - 2025-01-21
914

1015
### Added
1116

Src/Private/Get-RequiredModule.ps1

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,53 @@ function Get-RequiredModule {
44
Function to check if the required version of VMware PowerCLI is installed
55
.DESCRIPTION
66
Function to check if the required version of VMware PowerCLI is installed
7+
.NOTES
8+
Version: 0.1.1
9+
Author: Tim Carman
10+
Twitter: @tpcarman
11+
Github: tpcarman
712
.PARAMETER Name
813
The name of the required PowerShell module
914
.PARAMETER Version
1015
The version of the required PowerShell module
1116
#>
1217
[CmdletBinding()]
13-
14-
Param
15-
(
18+
Param (
19+
[CmdletBinding()]
1620
[Parameter(Mandatory = $true, ValueFromPipeline = $false)]
1721
[ValidateNotNullOrEmpty()]
18-
[String] $Name,
22+
[String]$Name,
1923

24+
[CmdletBinding()]
2025
[Parameter(Mandatory = $true, ValueFromPipeline = $false)]
2126
[ValidateNotNullOrEmpty()]
22-
[String] $Version
27+
[String]$Version
2328
)
29+
30+
begin {}
31+
2432
process {
25-
# Check if the required version of VMware PowerCLI is installed
26-
$RequiredModule = Get-Module -ListAvailable -Name $Name | Sort-Object -Property Version -Descending | Select-Object -First 1
27-
$ModuleVersion = "$($RequiredModule.Version.Major)" + "." + "$($RequiredModule.Version.Minor)"
28-
if ($ModuleVersion -eq ".") {
29-
throw "VMware PowerCLI $Version or higher is required to run the VMware Horizon As Built Report. Run 'Install-Module -Name $Name -MinimumVersion $Version' to install the required modules."
33+
# Convert required version to a [Version] object
34+
$RequiredVersion = [Version]$Version
35+
36+
# Find the latest installed version of the module
37+
$InstalledModule = Get-Module -ListAvailable -Name $Name |
38+
Sort-Object -Property Version -Descending |
39+
Select-Object -First 1
40+
41+
if ($null -eq $InstalledModule) {
42+
throw "VMware PowerCLI $Version or higher is required. Run 'Install-Module -Name $Name -MinimumVersion $Version -Force' to install the required modules."
3043
}
31-
if ($ModuleVersion -lt $Version) {
32-
throw "VMware PowerCLI $Version or higher is required to run the VMware Horizon As Built Report. Run 'Update-Module -Name $Name -MinimumVersion $Version' to update the required modules."
44+
45+
# Convert installed version to a [Version] object
46+
$InstalledVersion = [Version]$InstalledModule.Version
47+
48+
Write-PScriboMessage -Plugin "Module" -IsWarning "$($InstalledModule.Name) $InstalledVersion is currently installed."
49+
50+
if ($InstalledVersion -lt $RequiredVersion) {
51+
throw "VMware PowerCLI $Version or higher is required. Run 'Update-Module -Name $Name -MinimumVersion $Version -Force' to update the required modules."
3352
}
3453
}
54+
3555
end {}
36-
}
56+
}

Src/Public/Invoke-ASBuiltReport.VMware.Horizon.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
.DESCRIPTION
66
Documents the configuration of VMware Horizon in Word/HTML/XML/Text formats using PScribo.
77
.NOTES
8-
Version: 1.1.5
8+
Version: 1.1.5.1
99
Author: Chris Hildebrandt, Karl Newick
1010
Twitter: @childebrandt42, @karlnewick
1111
Editor: Jonathan Colon, @jcolonfzenpr

0 commit comments

Comments
 (0)