Welcome › Forums › General PowerShell Q&A › How to run a powershell script from any path using PSScriptRoot concept
I want to execute a powershell script from any path from local .
Here “src\Customization\Source” is the fixed path
$path = "C:\Programs\data\Git\tc-pdm\src\Customization\Source"
For running the abc.ps1 file we need to provide the whole path ” cd C:\Programs\data” and then “.\abc.ps1 ” in the powershell console
But now i should be able to run the abc.ps1 file even if the path is different “cd C:\Programs\temp1”.
I was thinking if we can use PSScriptRoot concept for this .
$PSScriptRoot will have the path where the current executing script resides. If the script is in the same location of the caller script, you can use it.
I would suggest to parameterize it giving a default value.
Thanks for the response Prasoon .
Do you have any idea about how to modify the above script using PSScriptRoot ?