Last active
October 5, 2021 17:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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