Open
Description
In PowerShell, profile scripts are used to import functionality whenever someone loads PowerShell.
Profile scripts can be distinct for each user and host, and will populate the PowerShell automatic variable $profile
.
This concept can be easily extended to loading a "Module Profile". This was first described in Posh.
At the end of a module's .psm1, it should check to see if file exists in the same directory as $profile
:
$MyModule = $myInvocation.MyCommand.ScriptBlock.Module
$MyModuleProfile = $profile | Split-Path | Join-Path -ChildPath "$MyModule.profile.ps1"
if (Test-Path $myModuleProfile) {
. $MyModuleProfile
}
Using .
to call the profile will include the Module Profile's functionality in the module
Using '&' to call the profile will simply run the Module Profile.