# How to get the path of the currently executing script in PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

## Output

PS C:\WINDOWS\system32> C:\Temp\TestPS.ps1
Path of the script : C:\Temp\TestPS.ps1

Please note that we are running the above script from the System32 directory and the output path is C:\temp. To get the script directory, we can use the Split-Path command. for example,

## Output

PS C:\WINDOWS\system32> C:\Temp\TestPS.ps1
Name of the script : TestPS.ps1`

When you run the above commands directly from the console, it won’t give any output because \$MyInvocation can only produce output when the script is invoked. For example,

Published on 02-Nov-2020 11:09:58