SPO.PowerShell.Predictor.psm1


$PSDefaultParameterValues.Clear()
Set-StrictMode -Version Latest

if ($true -and ($PSEdition -eq 'Desktop')) {
    throw "Windows PowerShell is not supported. Please install PowerShell Core 7.2 or higher version."
}

if ($true -and ($PSEdition -eq 'Core')) {
    if ($PSVersionTable.PSVersion -lt [Version]'7.2.0') {
        throw "Current SPO.PowerShell.Predictor version doesn't support PowerShell Core versions lower than 7.2.0. Please upgrade to PowerShell Core 7.2.0 or higher. "
    }
}

$psReadlineModule = Get-Module -Name PSReadLine
$minimumRequiredVersion = [version]"2.2.2"
$shouldImportPredictor = $true

if ($psReadlineModule -ne $null -and $psReadlineModule.Version -lt $minimumRequiredVersion) {
    $shouldImportPredictor = $false
    throw "This module requires PSReadLine version $minimumRequiredVersion. An earlier version of PSReadLine is imported in the current PowerShell session. Please open a new session before importing this module. "
}
elseif ($psReadlineModule -eq $null) {
    try {
        Import-Module PSReadLine -MiniumVersion $minimumRequiredVersion -Scope Global
    }
    catch {
        $shouldImportPredictor = $false
        throw "This module requires PSReadLine version $minimumRequiredVersion. Please install PSReadLine $minimumRequiredVersion or higher. "
    }
}

# Import the predictor module
if ($shouldImportPredictor) {
    try {
        Import-Module (Join-Path -Path $PSScriptRoot -ChildPath SPO.PowerShell.Predictor.dll);
        Write-Host "Module imported" -ForegroundColor Green
        Write-Warning "Make sure you either have SharePoint Online Management shell installed or have installed Microsoft.Online.SharePoint.PowerShell module for the cmdlets to work. If you have installed it already then ignore this warning.";
    }
    catch {
        Write-Error "An error occurred while importing the module. Details:"
        Write-Error $_
    }
}