While testing a PowerShell DSC script deployed by Azure Automation on an Azure Virtual Machine I ran against the following error message:
The command <command> was found in the module PowerShellGet, but the module could not be loaded.
What I tried to accomplish was automatically installing the PowerShell Az modules with the following PowerShell DSC script.
# Import DSC modules Import-DscResource -ModuleName "PowerShellGet" -ModuleVersion 2.2.5 Node $AllNodes.NodeName { PSModule "Az" { Ensure = "Present" Name = "Az" Repository = "PSGallery" InstallationPolicy = "Trusted" AllowClobber = $true Force = $true RequiredVersion = 5.6.0 } }
To solve this issue you also have to import the PackageManagement module because PowerShellGet has a dependency on this module. The correct version of the script is thus:
# Import DSC modules Import-DscResource -ModuleName "PackageManagement" -ModuleVersion 1.4.4 Import-DscResource -ModuleName "PowerShellGet" -ModuleVersion 2.2.5 Node $AllNodes.NodeName { PSModule "Az" { Ensure = "Present" Name = "Az" Repository = "PSGallery" InstallationPolicy = "Trusted" AllowClobber = $true Force = $true RequiredVersion = 5.6.0 } }
Update (March, 15th)
The PowerShellGet module has a specific dependency on version 1.4.4 of the PackageManagement module. You can see it defined in the manifest file (PowerShellGet.psd1).
RequiredModules = @(@{ModuleName = 'PackageManagement'; ModuleVersion = '1.4.4' })
Comments
Post a Comment