Skip to content

Commit 5b14a85

Browse files
Small improvements to PSD1/PSM1
1 parent bcc4c8b commit 5b14a85

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

PSWinReportingV2.psd1

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
ModuleName = 'PSEventViewer'
2121
Guid = '5df72a79-cdf6-4add-b38d-bcacf26fb7bc'
2222
}, @{
23-
ModuleVersion = '0.0.198'
23+
ModuleVersion = '0.0.211'
2424
ModuleName = 'PSSharedGoods'
2525
Guid = 'ee272aa8-baaa-4edf-9f45-b6d6f7d844fe'
2626
}, @{
2727
ModuleVersion = '0.1.13'
2828
ModuleName = 'PSWriteExcel'
2929
Guid = '82232c6a-27f1-435d-a496-929f7221334b'
3030
}, @{
31-
ModuleVersion = '0.0.145'
31+
ModuleVersion = '0.0.158'
3232
ModuleName = 'PSWriteHTML'
3333
Guid = 'a7bdf640-f5cb-4acf-9de0-365b322d245c'
3434
})

PSWinReportingV2.psm1

+50-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
11
#Get public and private function definition files.
22
$Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue -Recurse )
33
$Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue -Recurse )
4+
$Classes = @( Get-ChildItem -Path $PSScriptRoot\Classes\*.ps1 -ErrorAction SilentlyContinue -Recurse )
5+
$Enums = @( Get-ChildItem -Path $PSScriptRoot\Enums\*.ps1 -ErrorAction SilentlyContinue -Recurse )
46

5-
#Dot source the files
6-
Foreach ($import in @($Public + $Private)) {
7-
Try {
8-
. $import.fullname
9-
} Catch {
10-
Write-Error -Message "Failed to import function $($import.fullname): $_"
7+
$AssemblyFolders = Get-ChildItem -Path $PSScriptRoot\Lib -Directory -ErrorAction SilentlyContinue
8+
if ($AssemblyFolders.BaseName -contains 'Standard') {
9+
$Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\Standard\*.dll -ErrorAction SilentlyContinue )
10+
} else {
11+
if ($PSEdition -eq 'Core') {
12+
$Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\Core\*.dll -ErrorAction SilentlyContinue )
13+
} else {
14+
$Assembly = @( Get-ChildItem -Path $PSScriptRoot\Lib\Default\*.dll -ErrorAction SilentlyContinue )
1115
}
1216
}
13-
Export-ModuleMember -Function * -Alias *s
17+
$FoundErrors = @(
18+
Foreach ($Import in @($Assembly)) {
19+
try {
20+
Add-Type -Path $Import.Fullname -ErrorAction Stop
21+
} catch [System.Reflection.ReflectionTypeLoadException] {
22+
Write-Warning "Processing $($Import.Name) Exception: $($_.Exception.Message)"
23+
$LoaderExceptions = $($_.Exception.LoaderExceptions) | Sort-Object -Unique
24+
foreach ($E in $LoaderExceptions) {
25+
Write-Warning "Processing $($Import.Name) LoaderExceptions: $($E.Message)"
26+
}
27+
$true
28+
#Write-Error -Message "StackTrace: $($_.Exception.StackTrace)"
29+
} catch {
30+
Write-Warning "Processing $($Import.Name) Exception: $($_.Exception.Message)"
31+
$LoaderExceptions = $($_.Exception.LoaderExceptions) | Sort-Object -Unique
32+
foreach ($E in $LoaderExceptions) {
33+
Write-Warning "Processing $($Import.Name) LoaderExceptions: $($E.Message)"
34+
}
35+
$true
36+
#Write-Error -Message "StackTrace: $($_.Exception.StackTrace)"
37+
}
38+
}
39+
#Dot source the files
40+
Foreach ($Import in @($Private + $Public + $Classes + $Enums)) {
41+
Try {
42+
. $Import.Fullname
43+
} Catch {
44+
Write-Error -Message "Failed to import functions from $($import.Fullname): $_"
45+
$true
46+
}
47+
}
48+
)
49+
50+
if ($FoundErrors.Count -gt 0) {
51+
$ModuleName = (Get-ChildItem $PSScriptRoot\*.psd1).BaseName
52+
Write-Warning "Importing module $ModuleName failed. Fix errors before continuing."
53+
break
54+
}
55+
56+
Export-ModuleMember -Function '*' -Alias '*'

0 commit comments

Comments
 (0)