# Script Module manifest for module 'AzureAD.Standard.Preview'
# Generated by: Microsoft Corporation
# Generated on: 01/24/2017
# Updated on: 03/20/2019

Set-StrictMode -Version Latest

# Set up some helper variables to make it easier to work with the module
$script:PSModule = $ExecutionContext.SessionState.Module
$script:PSModuleDir = $script:PSModule.ModuleBase
$script:ADAssemblyRoot = 'Microsoft.Open.Azure.AD.CommonLibrary.dll'
$script:ADNestedAssemblies = @(

# Try to import the AD assembly at the same directory regardless fullclr or coreclr
$ADRootModulePath = Join-Path -Path $script:PSModuleDir -ChildPath $script:ADAssemblyRoot
$BinaryModuleDir = $script:PSModuleDir

if(-not (Test-Path -Path $ADRootModulePath))
    # Import the appropriate nested binary module based on the current PowerShell version
    if (($PSVersionTable.Keys -contains "PSEdition") -and ($PSVersionTable.PSEdition -eq 'Desktop')) 
        $BinaryModuleDir = Join-Path -Path $script:PSModuleDir -ChildPath 'net471'
        Write-Debug -Message "Loading module in fullclr folder: 'net471' ..."    
        $BinaryModuleDir = Join-Path -Path $script:PSModuleDir -ChildPath 'netstandard2.0'
        Write-Debug -Message "Loading module in coreclr folder: 'netstandard2.0' ..."

# Load root assembly first
$ADRootModulePath = Join-Path -Path $BinaryModuleDir -ChildPath $script:ADAssemblyRoot
$ADRootModule = Import-Module -Name $ADRootModulePath -PassThru

# Load all nested assemblies
foreach($assembly in $script:ADNestedAssemblies)
    $ADModulePath = Join-Path -Path $BinaryModuleDir -ChildPath $assembly
    Import-Module -Name $ADModulePath -PassThru

# When the module is unloaded, remove the nested binary module that was loaded with it
    $script:PSModule.OnRemove = {
        Remove-Module -ModuleInfo $ADRootModule