AzureAD.Standard.Preview.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# 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 = @(
    'Microsoft.Open.AzureAD16.Graph.PowerShell.dll', 
    'Microsoft.Open.AzureAD16.Graph.PowerShell.Custom.dll', 
    'Microsoft.Open.AzureAD16.Graph.Client.dll', 
    'Microsoft.Open.MS.GraphV10.PowerShell.Custom.dll', 
    'Microsoft.Open.MS.GraphV10.PowerShell.dll', 
    'Microsoft.Open.MS.GraphV10.Client.dll')

# 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' ..."    
    }else{
        $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
if($ADRootModule)
{
    $script:PSModule.OnRemove = {
        Remove-Module -ModuleInfo $ADRootModule
    }
}