PSUtil.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
<#
    .NOTES
    --------------------------------------------------------------------------------
     Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.143
     Generated on: 20.09.2017 00:05
     Generated by: Friedrich Weinmann
     Organization: Infernal Associates ltd.
    --------------------------------------------------------------------------------
    .DESCRIPTION
        Script generated by PowerShell Studio 2017
#>



$script:PSUtilModuleRoot = $PSScriptRoot

$script:doDotSource = Get-PSFConfigValue -FullName PSUtil.Import.DoDotSource -Fallback $false

#region Helper function
function Import-PSUFile
{
    <#
        .SYNOPSIS
            Loads files into the module on module import.
         
        .DESCRIPTION
            This helper function is used during module initialization.
            It should always be dotsourced itself, in order to proper function.
         
        .PARAMETER Path
            The path to the file to load
         
        .EXAMPLE
            PS C:\> . Import-PSUFile -File $function.FullName
     
            Imports the file stored in $function according to import policy
    #>

    [CmdletBinding()]
    Param (
        [string]
        $Path
    )
    
    if ($script:doDotSource) { . $Path }
    else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($Path))), $null, $null) }
}
#endregion Helper function


# Perform Actions before loading the rest of the content
. Import-PSUFile -Path "$PSUtilModuleRoot\internal\scripts\preload.ps1"

#region Load functions
foreach ($function in (Get-ChildItem "$PSUtilModuleRoot\functions" -Recurse -File -Filter "*.ps1"))
{
    . Import-PSUFile -Path $function.FullName
}
#endregion Load functions

# Perform Actions after loading the module contents
. Import-PSUFile -Path "$PSUtilModuleRoot\internal\scripts\postload.ps1"