2015-02-11 103 views
3

呼叫PowerShell的我打電話從一個命令腳本PS提示符下使用以下行從命令提示符相對路徑

powershell "& 'c:/script.ps1'" 

不過,我需要的腳本是相對於命令提示符窗口。因此,如果命令提示符看着C:那麼腳本將有效地

powershell "& 'script.ps1'" 

是否有辦法注入的相對路徑?

回答

6
powershell "& '%cd%\script.ps1'" 

,或者如果你的意思是使用來自該批處理文件是在PowerShell腳本啓動目錄,那麼你會通過把這種類型的線在你的PS腳本的開頭使用參數...

param([string]$Directory) 

然後在命令行中調用像填充它...

Powershell C:\script.ps1 -Directory %cd% 
+0

%cd%working - 感謝您的詳細回覆。 – heymega 2015-02-13 13:33:29

0

注入相對路徑,你開始你的批處理文件,你必須編寫

powershell "& '%~dp0\script.ps1'"