CMAWS.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
#Requires -version 3.0
# This module file simply dot sources all .ps1 files in the Functions subfolder.
# This simplifies management of the modules functions.

# Sets the Script Path variable to the scripts invocation path.
$ScriptPath = Split-Path -Path $MyInvocation.MyCommand.Path

$Paths = @('Functions', 'Intellisense')
foreach ($Path in $Paths)
{
    try
    {
        $ItemPath = '{0}\{1}' -f $ScriptPath, $Path

        # Retrieve all .ps1 files in the Functions subfolder
        $Files = Get-ChildItem -Path $ItemPath -Name '*.ps1' -Attributes !D

        # Dot source all .ps1 file found
        foreach ($FunctionFile in $Files)
        {
            . "$($ItemPath)\$FunctionFile"
        }
    }
    catch
    {
        Write-Warning -Message ('{0}: {1}' -f $FunctionFile, $_.Exception.Message)
        Continue
    }
}