Better handling of module version checks

If the module is not loaded, and autoloading does not occur before the `Get-HVModuleVersion` call, the result might be an empty string. This gives a chance to force loading the module and error if it is not available.
This commit is contained in:
Rob Nelson
2021-05-17 15:41:54 -04:00
committed by GitHub
parent 7dd8f4cabc
commit 0a94dd4658

View File

@@ -55,7 +55,10 @@ function Get-ViewAPIService {
}
function Get-HVModuleVersion {
$hvModules = @( Get-Module -Name "Vmware.VimAutomation.HorizonView" -ErrorAction "SilentlyContinue" );
if (-not (Get-Module -Name "Vmware.VimAutomation.HorizonView" -ErrorAction "SilentlyContinue") ) {
Import-Module -Name "Vmware.VimAutomation.HorizonView" -ErrorAction Stop
}
$hvModules = @( Get-Module -Name "Vmware.VimAutomation.HorizonView" -ErrorAction SilentlyContinue);
return $($hvModules.version | measure -Maximum).Maximum
}