-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
PSAutomator.psm1
54 lines (51 loc) · 2.32 KB
/
PSAutomator.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
#Get public and private function definition files.
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue -Recurse )
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue -Recurse )
$AssemblyFolders = Get-ChildItem -Path $PSScriptRoot\Lib -Directory -ErrorAction SilentlyContinue
if ($AssemblyFolders.BaseName -contains 'Standard') {
$Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\Standard\*.dll -ErrorAction SilentlyContinue )
} else {
if ($PSEdition -eq 'Core') {
$Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\Core\*.dll -ErrorAction SilentlyContinue )
} else {
$Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\Default\*.dll -ErrorAction SilentlyContinue )
}
}
$FoundErrors = @(
Foreach ($Import in @($Assembly)) {
try {
Add-Type -Path $Import.Fullname -ErrorAction Stop
} catch [System.Reflection.ReflectionTypeLoadException] {
Write-Warning "Processing $($Import.Name) Exception: $($_.Exception.Message)"
$LoaderExceptions = $($_.Exception.LoaderExceptions) | Sort-Object -Unique
foreach ($E in $LoaderExceptions) {
Write-Warning "Processing $($Import.Name) LoaderExceptions: $($E.Message)"
}
$true
#Write-Error -Message "StackTrace: $($_.Exception.StackTrace)"
} catch {
Write-Warning "Processing $($Import.Name) Exception: $($_.Exception.Message)"
$LoaderExceptions = $($_.Exception.LoaderExceptions) | Sort-Object -Unique
foreach ($E in $LoaderExceptions) {
Write-Warning "Processing $($Import.Name) LoaderExceptions: $($E.Message)"
}
$true
#Write-Error -Message "StackTrace: $($_.Exception.StackTrace)"
}
}
#Dot source the files
Foreach ($Import in @($Private + $Public)) {
Try {
. $Import.Fullname
} Catch {
Write-Error -Message "Failed to import functions from $($import.Fullname): $_"
$true
}
}
)
if ($FoundErrors.Count -gt 0) {
$ModuleName = (Get-ChildItem $PSScriptRoot\*.psd1).BaseName
Write-Warning "Importing module $ModuleName failed. Fix errors before continuing."
break
}
Export-ModuleMember -Function '*' -Alias '*'