Finding Current Script Folder

by Oct 18, 2013

Beginning in PowerShell 3.0, there is a very easy way of determining the folder a script is located in: $PSScriptRoot. This variable always holds the folder path a given script is stored in.

This way, it is simple to load additional resources like other scripts. This code would load a second script called myFunctions.ps1 that is located in the same folder:

"$PSScriptRoot\myFunctions.ps1" 

Just don't forget to dot-source the path (the dot before the path). Else, the path name will be outputted (and not executed).

Twitter This Tip! ReTweet this Tip!