Reusing functions in PowerShell

One thing that struck me as kind of odd when I first started to look at PowerShell and how to include other script files in order to gain access to functions in that other script is that all examples I found use an absolute path to include scripts (ex: “. C:\Some\Path\Script.ps1”). At least for me, using absolute paths is never good so I tried a relative path like this: “.\Script.ps1”

The result is no errors running the script but no functions from the script are defined outside the script. “. Script.ps1” is even worse since it does not even execute the script. What you have to do is this: “. .\Script.ps1”

Remember to use “double dots” with space between them! And I cannot understand why all tutorials I found use the absolute path approach since relative inclusion is much more likely to work.

Comments (0)

Skip to main content