PsSqlClient.psm1

$LoadedAssemblies = [System.AppDomain]::CurrentDomain.GetAssemblies()

@(
    "$PSScriptRoot\runtimes\win\lib\netstandard2.1\Microsoft.Data.SqlClient.dll",
    "$PSScriptRoot\Microsoft.Identity.Client.dll",
    "$PSScriptRoot\Azure.Core.dll",
    "$PSScriptRoot\Azure.Identity.dll",
    "$PSScriptRoot\Microsoft.SqlServer.Server.dll"
    ) | ForEach-Object {
        [System.IO.FileInfo] $RequiredAssemblyPath = $_
        If ( -not $RequiredAssemblyPath.Exists ) {
            Write-Error "Build issue: '$RequiredAssemblyPath' does not exist."
        }
        $LoadedAssembly = $LoadedAssemblies | Where-Object Location -Like "*$( $RequiredAssemblyPath.Name )"

        if ( $LoadedAssembly ) {
            Write-Warning "Assembly '$( $LoadedAssembly.GetName() )' already loaded from '$( $LoadedAssembly.Location )'. Skip adding defined dll."
        }
        else {
            try {
                Add-Type -Path $RequiredAssemblyPath
            }
            catch [System.IO.FileLoadException] {
                Write-Error "$( $_.Exception ) while adding assembly '$( $RequiredAssemblyPath.Name )'"
            }
        }
    }