How to find location/path of current script in powershell
<p>I have a script (script1.ps1) that lies in C:\FolderA</p>

<p>What powershell code can I insert in the script, that it will print what ever current location/path of the script. (The goal is to make this script portable)</p>

<p>ie: </p>

<p>-When in folderA, the code will print C:\FolderA (full-path)</p>

<p>-When Script1.ps1 is moved to C:\FolderB\FolderC and run, it prints the full path of C:\FolderB\FolderC</p>

<p>Any help would be much appreciated.</p>

<p>Thanks</p>

<hr>

<p>Thanks to @Nkosi and @Kori Gill </p>

<p>The answer I was looking for was $PSScriptRoot </p>

<p>One thing to note, is that I noticed I had to define a variable first inside the script before running the script:</p>

<pre><code>$Path = $PSScriptRoot

$Path
</code></pre>

<p>with this it worked otherwise it didnt</p>