grpCompInfo.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
# Get all Public and Private function files.
$Public = @(
    Get-ChildItem -Path "$PSScriptRoot\Public\*.ps1" -Recurse -ErrorAction Stop
)
$Private = @(
    Get-ChildItem -Path "$PSScriptRoot\Private\*.ps1" -Recurse -ErrorAction Stop
)

# Dot source the files.
foreach ($functionFile in @($Public + $Private)) {
    try {
        . $functionFile.fullname
    }
    catch {
        Write-Warning -Message "Oops... Something went wrong!"
        Write-Host ''
        
        Write-Host -ForegroundColor Red "Error Type:"
        $PSItem.GetType().FullName
        Write-Host ''
        
        Write-Host -ForegroundColor Red "Error Position:"
        $PSItem.InvocationInfo.PositionMessage.Split("+")[0].Trim()
        Write-Host ''
        
        Write-Host -ForegroundColor Red "Error Line:"
        $PSItem.InvocationInfo.Line.Trim()
        Write-Host ''

        Write-Host -ForegroundColor Red "Error Message:"
        $PSItem.Exception.Message
        Write-Host ''

        EXIT 1
    }
}