forked from ilude/WindowsPowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Modules.psm1
51 lines (42 loc) · 1.24 KB
/
Modules.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
###########################
#
# Reload-Module
#
###########################
function Reload-Module($ModuleName) {
if((get-module -all | where{$_.name -eq "$ModuleName"} | measure-object).count -gt 0) {
remove-module $ModuleName
Write-Verbose "Module $ModuleName Unloaded"
$pwd = Get-ScriptDirectory
$file_path = $ModuleName;
if(Test-Path (join-Path $pwd "$ModuleName.psm1")) {
$file_path = (join-Path $pwd "$ModuleName.psm1")
}
import-module "$file_path" -DisableNameChecking -verbose:$false
Write-Verbose "Module $ModuleName Loaded"
}
else {
Write-Warning "Module $ModuleName Doesn't Exist"
}
}
###########################
#
# Initialize-Modules
#
###########################
function Initialize-Modules {
Get-Module | Where-Object { Test-Method $_.Name $_.Name } | foreach {
$functionName = $_.Name
Write-Verbose "Initializing Module $functionName"
Invoke-Expression $functionName | Out-Null
}
}
###########################
#
# Test-Method
#
###########################
function Test-Method($moduleName, $functionName) {
(get-command -module $moduleName | Where-Object { $_.Name -eq "$functionName" } | Measure-Object).Count -eq 1;
}
Export-ModuleMember Reload-Module, Initialize-Modules, Test-Method, Invoke-Method