forked from dataplat/dbachecks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbachecks.psm1
56 lines (47 loc) · 1.92 KB
/
dbachecks.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
$script:ModuleRoot = $PSScriptRoot
$VerbosePreference = "Continue"
function Import-ModuleFile {
[CmdletBinding()]
Param (
[string]
$Path
)
if ($doDotSource) { . $Path }
else {
try {
$ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($Path))), $null, $null)
}
catch {
Write-Warning "Failed to import $Path"
}
}
}
# Detect whether at some level dotsourcing was enforced
$script:doDotSource = $false
if ($dbachecks_dotsourcemodule) { $script:doDotSource = $true }
if ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsPowerShell\dbachecks\System" -Name "DoDotSource" -ErrorAction Ignore).DoDotSource) { $script:doDotSource = $true }
if ((Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\WindowsPowerShell\dbachecks\System" -Name "DoDotSource" -ErrorAction Ignore).DoDotSource) { $script:doDotSource = $true }
# Execute Preimport actions
if($IsLinux){
Write-Verbose "Loading preimport in linux"
. Import-ModuleFile -Path "$ModuleRoot/internal/scripts/preimport.ps1"
}else{
. Import-ModuleFile -Path "$ModuleRoot\internal\scripts\preimport.ps1"
}
# Import all internal functions
foreach ($function in (Get-ChildItem "$ModuleRoot\internal\functions\*.ps1")) {
. Import-ModuleFile -Path $function.FullName
}
# Import all public functions
foreach ($function in (Get-ChildItem "$ModuleRoot\functions\*.ps1")) {
. Import-ModuleFile -Path $function.FullName
}
# Execute Postimport actions
if($IsLinux){
Write-Verbose "Loading postimport in linux"
. Import-ModuleFile -Path "$ModuleRoot/internal/scripts/postimport.ps1"
}else{
. Import-ModuleFile -Path "$ModuleRoot\internal\scripts\postimport.ps1"
}
if (-not (Test-Path Alias:Update-Dbachecks)) { Set-Alias -Scope Global -Name 'Update-Dbachecks' -Value 'Update-DbcRequiredModules' }
$VerbosePreference = "SilentlyContinue"