powershellincluderelative-path

Include relative files in PowerShell


I would like to include script files with such pseudo syntax:

Include '.\scripA.ps1'

But the only thing I have found is some thing like this:

$thisScript = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
. ($thisScript + '.\scriptA.ps1')

that is ugly.

Is there some nice way to include scripts with relative paths?


Solution

  • Unfortunately no, there is no good way. PowerShell doesn't really support this idea very well at all in V1. Really the approach you are taking is the best approach