Skip to content

Instantly share code, notes, and snippets.

@Rugby-Ball
Last active October 5, 2021 17:20
Show Gist options
  • Select an option

  • Save Rugby-Ball/6a3d24e3889f9e274434f548ec7d2e5b to your computer and use it in GitHub Desktop.

Select an option

Save Rugby-Ball/6a3d24e3889f9e274434f548ec7d2e5b to your computer and use it in GitHub Desktop.
Use this Snippet at the beginning of your PowerShell to check for a Module Dependency and install if its missing. #Snippet #Public
# PowerShell Module Dependency check.
#
$modulename = "SqlServer" #PowerShell Module Dependency to check
if(-not(Get-Module -name $modulename))
{
if(Get-Module -ListAvailable |
Where-Object { $_.name -eq $modulename })
{
Import-Module -Name $modulename
$true
} #end if module available then import
else {
Echo " Installing the PowerShell Module: $modulename "
Install-Module -name $modulename
} #module not available. Install Module
} # end 'if not' module statement.
#else { Echo "Powershell Module is already installed and loaded"} #module already loaded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment