Performance.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
[CmdletBinding()] 
param(
)

# Because these are set once in a script scope (modules and functions are all considered in one script scope)
# they will be effective in every function, and won't override or be overridden by changes in parent scopes.
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

foreach ($fileName in (Get-ChildItem $PSScriptRoot "*.ps1" -Recurse)) {
    try {
        Write-Verbose "Loading function from path '$fileName'."
        if ($Host.Name -ne "Default Host") {
            # Allows debugging
            . $fileName.FullName
        } else {
            # Faster but no debugging
            Invoke-Expression ([System.IO.File]::ReadAllText($fileName.FullName))
        }
    } catch {
        Write-Error $_
    }
}

# This is required for nested modules, to be re-declared in the parent module
Set-Variable -Scope Script -Name PerformanceRecord -Value @{}