Functions/Import-VoleerPackageFunction.ps1
<#
.SYNOPSIS This function imports a function residing in a Voleer package. .DESCRIPTION This function imports a function residing in a Voleer package. This function is intended to be used within the recommended package file structure. If the recommended package file structure is not used, unexpected results may occur. #> function Import-VoleerPackageFunction { [CmdletBinding(PositionalBinding=$true)] [OutputType()] param ( [Parameter(Mandatory=$true, Position=0)] [ValidateNotNullOrEmpty()] [String]$FunctionName ) # Check that this function is being called from a script if ([String]::IsNullOrWhiteSpace($MyInvocation.ScriptName)) { Write-Error "Import-VoleerPackageFunction must be called from a package task script." return } # Retrieve the parent path of the script $scriptParentPath = Split-Path -Path $MyInvocation.ScriptName -Parent # Construct the path to the function file $functionFilePath = Join-Path -Path $scriptParentPath -ChildPath "..\..\functions\$($FunctionName).ps1" # Check that the function file exists if (!(Test-Path -Path $functionFilePath -ErrorAction SilentlyContinue)) { Write-Error "The path to the function file '$($functionFilePath)' does not exist." return } # Import the function . $functionFilePath Write-Information "The function '$($FunctionName)' has been imported from the package." } |