BIGCommonPS5.psm1

function PS5Check {
    if ($PSVersionTable.PSVersion -notlike "5.*") {
        throw "You need to be running PowerShell 5 to use this function"
    }
}

# MSOL
function checkifMsolModuleExists {
    if (!(Get-Module -ListAvailable -Name MSOnline)) {
        Write-Host "You don't have the MSOnline module installed. `nDon't worry though, I'll install it for you" -ForegroundColor Yellow
        Install-Module -Name MSOnline
    } elseif (Get-Module -ListAvailable -Name MSOnline) {
        Write-Host "MSOnline is installed" -ForegroundColor Green
        Write-Host "Importing Module" -ForegroundColor Green
        Import-Module -Name MSOnline
        Write-Host "If the authentication box doesn't appear, check behind the VSCode/ISE window" -ForegroundColor Black -BackgroundColor White
    }
}

function connect-msol {
    PS5Check
    checkifMsolModuleExists
    Connect-MsolService
}

# AzureAD

function checkifAzureADModuleExists {
    if (!(Get-Module -ListAvailable -Name AzureAD)) {
        Write-Host "You don't have the AzureAD module installed. `nDon't worry though, I'll install it for you" -ForegroundColor Yellow
        Install-Module -Name AzureAD
    } elseif (Get-Module -ListAvailable -Name AzureAD) {
        Write-Host "AzureAD module is installed" -ForegroundColor Green
        Write-Host "Importing Module" -ForegroundColor Green
        Import-Module -Name AzureAD
        Write-Host "If the authentication box doesn't appear, check behind the VSCode window" -ForegroundColor Black -BackgroundColor White
    }
}

function connect-aad {
    PS5Check
    checkifAzureADModuleExists
    Connect-AzureAD
}