Skip to main content

How to check if a particular PowerShell is installed; if it isn't, install and load it.

# Check if AzureAD Module is installed, if not... install it
$moduleName = "AzureAD"
if ($null -eq (Get-Module -ListAvailable -Name $moduleName))
{
    Write-Output "Installing $moduleName module for CurrentUser..."
    Install-Module "AzureAD" -Scope CurrentUser
}

Import-Module $moduleName

# ...
# use the module...
# ...