PreMyProfileModuleProcess.ps1


# References:
# 1. Below are the list of predefined vars that can be used:
# - $PSScriptRoot [System defined] The folder path for current scipt file, NOT the caller script to call this function

<#
.SYNOPSIS
Invoke a script file in MyProfile module's caller scope.
 
.DESCRIPTION
Invoke a script file in MyProfile module's caller scope. Any exception is caught and print to host.
One major purpose of this function is to invoke script in MyProfile module's caller scope from MyProfile module scope.
 
.PARAMETER scriptPaths
The list of full path of the ps script file to run.
#>

function Invoke-ScriptInMyProfileModuleCallerScope
{
    param(
        [Parameter(Position=0, Mandatory=$true)]
        [string[]] $scriptPaths
    )

    $scriptPaths | % {
        $curScriptPath = $_
        if ((-NOT [string]::IsNullOrWhiteSpace($curScriptPath)) -AND (Test-Path $curScriptPath) -AND $curScriptPath.EndsWith('.ps1'))
        {
            try {
                . $curScriptPath
            }
            catch {
                Write-Host "Failed to run script $curScriptPath in MyProfile module's caller scope." -ForegroundColor Red
                Write-Host $_
            }
        }
    }
}

# As there is no customizable post action after install MyProfile module, the best way is to do the post install actions before import module.
& "$PSScriptRoot\PostInstall.ps1"