-
Notifications
You must be signed in to change notification settings - Fork 1
/
JklPoshToolbox.psm1
70 lines (54 loc) · 1.85 KB
/
JklPoshToolbox.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
59
60
61
62
63
64
65
66
67
68
69
70
<#
.NOTES
Modified: 2023-11-19
By: Jackson Brumbaugh
#>
$ModuleLocation = $PSScriptRoot
$ModuleName = Split-Path $ModuleLocation -Leaf
$DoNotExportFolderNameArray = @(
"Help"
)
$ExportFolderNameArray = @(
"Main",
"Dev"
)
$LoadFromFolderNameArray = @(
$ModuleLocation
)
foreach ( $ThisFolder in ($DoNotExportFolderNameArray + $ExportFolderNameArray) ) {
$LocationName = Join-Path $ModuleLocation ("*" + $ThisFolder + "*")
if ( Test-Path $LocationName ) {
$LoadFromFolderNameArray += $LocationName
} # End block:if LocationName was found
}# End block:foreach Folder (both Export + DoNotExport)
foreach ( $ThisFolderName in $LoadFromFolderNameArray ) {
$isThisFolderExported = $true
<#
Use a match vs a hard -in check in case i got lazy with the folder names
e.g. "Help" being listed in the array while the full folder name is HelperFuncs
#>
foreach ( $ThisDoNotExportKeyword in $DoNotExportFolderNameArray ) {
if ( $ThisFolderName -match $ThisDoNotExportKeyword ) {
$isThisFolderExported = $false
}
} # End block:foreach Do Not Export Keyword
<#
DO NOT USE -Recurse
Otherwise the HelperCmds children will be exported
#>
foreach ( $ThisPs1File in ( Get-ChildItem $ThisFolderName\*.ps1 ) ) {
# Dot-Sourcing "loads" the *.ps1 file into the module
. $ThisPs1File.FullName
if ( $isThisFolderExported ) {
$FunctionName = $ThisPs1File.BaseName
# Exporting the function from the file allows users of the module to run the function
Export-ModuleMember -Function $FunctionName
} # End block:if Export it
} # End block:foreach *.ps1 file
} # End block:foreach Folder to Load
$Aliases = (Get-Alias).Where{ $_.Source -eq $ModuleName }
$AliasNames = $Aliases.Name -replace "(.*) ->.*","`$1"
foreach ( $Alias in $AliasNames ) {
# Lets users use / see the alias
Export-ModuleMember -Alias $Alias
}