Patch/Cmdlets/Misc/Test-SqlServerLoaded.ps1

function Test-SqlServerLoaded {
    try {
        Get-Command "invoke-sqlcmd" -ErrorAction Stop | Out-Null
    }
    catch {
        Write-Warning "SqlServer module is not installed. Will try to install..."
        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
        Install-Module SqlServer -Force
        Import-Module SqlServer -Force
    }
    Write-Verbose "SqlServer module loaded"
}
Export-ModuleMember -Function Test-SqlServerLoaded