PrateekKumarSingh / AzViz

⚡ ☁ Azure Visualizer aka 'AzViz' : A #powershell module to automatically generate Azure resource topology diagrams by just typing a PowerShell cmdlet and passing the name of one or more Azure Resource groups
MIT License
587 stars 146 forks source link

Best Practices - RequiredModules #25

Closed TheTaylorLee closed 3 years ago

TheTaylorLee commented 3 years ago

Your "Script Module" file "AzViz.psm1" is installing PSGraph and AZ modules if not found when your module loads. This goes against best practices and shouldn't be handled there. This creates a situation where someone might have this module load from another source and it starts installing modules that they didn't intend to install, and they can't find what module is installing those other modules.

Best Practice would be to use your Module Manifest to specify required modules. In that scenario the offending module that is installing other modules becomes more discoverable.

Remove This ##Please

# verify dependent modules are loaded $DependentModules = 'PSGraph', 'az' $Installed = Import-Module $DependentModules -PassThru -ErrorAction SilentlyContinue | Where-Object { $_.name -In $DependentModules } $Missing = $DependentModules | Where-Object { $_ -notin $Installed.name } if ($Missing) { Write-Verbose " [+] Module dependencies not found [$Missing]. Attempting to install." Install-Module $Missing -Force -AllowClobber -Confirm:$false -Scope CurrentUser Import-Module $Missing }

-/u/SpacezCowboy

PrateekKumarSingh commented 3 years ago

@TheTaylorLee this has been fixed in recent commit to this repository. Closing the issue now.