Closed nzRegularIT closed 1 year ago
I have written an example of using Get-Module instead of Get-InstalledModule here: https://github.com/nzRegularIT/powershell-module-for-vmware-cloud-foundation-password-management/tree/nzRegularIT-patch-testVcfPwMgt
Another alternative would be to define the required modules in the manifest like https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_module_manifests?view=powershell-7.3#requiredmodules
This setting specifies modules that must be in the global session state. If the required modules aren't in the global session state, PowerShell imports them. If the required modules aren't available, the Import-Module command fails.
# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(
@{
ModuleName = 'VMware.PowerCLI'
ModuleVersion = '13.0.0'
}
@{
ModuleName = 'VMware.vSphere.SsoAdmin'
ModuleVersion = '1.3.9'
}
@{
ModuleName = 'PowerVCF'
ModuleVersion = '2.3.0'
}
@{
ModuleName = 'PowerValidatedSolutions'
ModuleVersion = '2.3.0'
}
)
Our documentation currently assumes that the module and dependencies are installed from the PowerShell Gallery; however, there is an opportunity to enhance the documentation to cover a disconnected / dark-site installation example.
Will provide an update soon on next steps, but we have planned to add the RequiredModules
to the manifest to make this simpler.
To be addressed in https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/63.
Note: The docs will be updated for the simpler online and offline installation before this is released in the next version.
I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Code of Conduct
VMware Cloud Foundation
v4.5
PowerShell Version
PowerShell Core 7.2.8
PowerCLI Version
13.1.0.21624340
Module Version
1.1.0.1008
PowerValidatedSolutions Version
2.3.0.1007
PowerVCF Version
2.3.0.1004
Guest Operating System
Windows Server 2019
Environment Details
Modules have been installed to the system via Windows PowerShell 5.1, to the all users scope. They are installed to "C:\Program Files\WindowsPowerShell\Modules"
PowerShell Core also reads in modules from this location, the value of $env:PSModulePath = "C:\Users\user\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\7\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules"
Description
Test-VcfPasswordManagementPrereq reports [ERROR] PowerShell Module: VMware.PowerCLI 13.0.0 minimum required version is not installed
Modules have been imported in PS 7.2.8 admin session: Import-Module -Name VMware.PowerCLI Import-Module -Name VMware.vSphere.SsoAdmin Import-Module -Name PowerVCF Import-Module -Name PowerValidatedSolutions Import-Module -Name VMware.CloudFoundation.PasswordManagement
Error or Debug Output
[ERROR] PowerShell Module: VMware.PowerCLI 13.0.0 minimum required version is not installed.
Get-Module -ListAvailable reports modules as available (see attached).
modules under ps core 7.2.8.log
Expected Behavior
Test-VcfPasswordManagementPrereq should return output as below:
[06-26-2023_13:03:30] [INFO] PowerShell Module: VMware.PowerCLI 13.1.0.21624340 is installed and supports the minimum required version. [06-26-2023_13:03:33] [INFO] PowerShell Module: VMware.vSphere.SsoAdmin 1.3.9 is installed and supports the minimum required version. [06-26-2023_13:03:36] [INFO] PowerShell Module: PowerVCF 2.3.0.1004 is installed and supports the minimum required version. [06-26-2023_13:03:39] [INFO] PowerShell Module: PowerValidatedSolutions 2.3.0.1007 is installed and supports the minimum required version.
Actual Behavior
Test-VcfPasswordManagementPrereq output:
[06-26-2023_13:19:33] [ERROR] PowerShell Module: VMware.PowerCLI 13.0.0 minimum required version is not installed.
Steps to Reproduce
Open PowerShell Core 7.2.8 Run Test-VcfPasswordManagementPrereq
Log Fragments and Files
No response
Screenshots
No response
References
Test-VcfPasswordManagementPrereq uses the PowerShell command Get-InstalledModule, which gets a list of modules on the computer that were installed by PowerShellGet.
This command unfortunately assumes that the modules have been installed via PowerShellGet.
We have two systems where modules are not installed via PowerShellGet, and both show similar issues with Test-VcfPasswordManagementPrereq
An alternative that might cover all these scenarion could be: Get-Module or Get-Module -ListAvailable, similar to https://stackoverflow.com/questions/28740320/how-do-i-check-if-a-powershell-module-is-installed