I'm calling a PS script from Command Prompt using the following line
powershell "& 'c:/script.ps1'"
However I need the script to be relative to the command prompt window. So if command prompt was looking at C:
then the script would effectively be
powershell "& 'script.ps1'"
Is there a way to inject the relative path?
powershell "& '%cd%\script.ps1'"
or if you mean to use the directory from which the batch file was launched in the powershell script then you would use a parameter by putting this type of line at the start of your PS script...
param([string]$Directory)
Then populating it from the command line invocation like...
Powershell C:\script.ps1 -Directory %cd%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With