This is one reason we dot source our larger scripts. It also has the advantage of code reuse and makes keeping them under source control easier.
Set-Location c:\scripts\adaxes
".\My-Script1.ps1", ".\My-Script2.ps1"| ForEach-Object {
if (!(Test-Path -Path $_)) {
try {
throw [System.IO.FileNotFoundException]::new("Missing helper script $_.")
}
catch {
$Context.LogException($_.Exception)
throw
}
}
else {
# dot source the helper scripts
. $_
}
}