Created
December 8, 2020 11:33
-
-
Save Clickbaitcake/394d9deef1e5dd664bda121a594dc44a to your computer and use it in GitHub Desktop.
Checks for the installation of a PowerShell module and tries to install it if its missing.
This file contains 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
#Usage: CheckModule -ModuleName ABC123 | |
function CheckModule{ | |
param($ModuleName) | |
if (Get-Module -ListAvailable -Name $ModuleName) { | |
Write-Host -ForegroundColor Green "$($ModuleName) exists" | |
} | |
else{ | |
Write-Host -ForegroundColor Red "$($ModuleName) does not exist. Attemping install..." | |
try{ | |
Install-Module $($ModuleName) -Confirm:$False -Force} | |
catch{ | |
Write-Host -ForegroundColor red "Could not install $($ModuleName) because of $error"} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment