internal/functions/test-assembliesloaded.ps1

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
<#
.SYNOPSIS
Test if any D365 assemblies are loaded
 
.DESCRIPTION
Test is any D365 assemblies are loaded into memory and will be a blocking issue
 
.EXAMPLE
PS C:\> Test-AssembliesLoaded
 
This will test in any D365 specific assemblies are loaded into memory.
If is, a Stop-PSFFunction test will state that we should stop execution.
 
.NOTES
Author: Mötz Jensen (@Splaxi)
 
#>


function Test-AssembliesLoaded {
    [CmdletBinding()]
    [OutputType()]
    param (
    )

    Invoke-TimeSignal -Start

    $assembliesLoaded = [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object Location -ne $null

    $assembliesBlocking = $assembliesLoaded.location -match "AOSService|Dynamics|PackagesLocalDirectory"

    if ($assembliesBlocking.Count -gt 0) {
        Stop-PSFFunction -Message "Stopping because some assembly (DLL) files seems to be loaded into memory." -StepsUpward 1
        return
    }

    Invoke-TimeSignal -End
}