2015-04-28 57 views
1

我正在使用批處理腳本讀取某些參數並啓動PowerShell腳本,該腳本需要輸入參數。使用批處理腳本中的參數運行PowerShell腳本

我迄今所做的:

Set /p arg1 = Type in a name for the data: 

Set /p arg2 = Type in the directory of the project: 

Set /p arg3 = Type in the programming language : 

Set /p arg4 = Type in a version for the metric data: 

SET ThisScriptsDirectory=%~dp0 
SET PowerShellScriptPath=%ThisScriptsDirectory%Metrics.ps1 

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' 'arg1' 'arg2' 'arg3' 'arg4'"; 

Unfortunally PowerShell腳本不接受參數。

+0

這個問題在[SO](http://stackoverflow.com/questions/19335004/how-to-run-a-powershell已回答-script-從-A-批處理文件)。我真的會遵循@deadlydog的鏈接。他的[博客](http://blog.danskingdom.com/allow-others-to-run-yow-powershell-scripts-from-a-batch-file-they-will-love-you-for-it/)非常好。 –

+0

謝謝,我會記住 – Arturka1

回答

2
PowerShell -NoProfile -ExecutionPolicy Bypass -file "%PowerShellScriptPath%" %arg1% %arg2% .... 
2

您的變量名稱有一個尾隨空格(「任何<空間>」)。前失去了空間和平等之後登錄:

Set /p arg1=Type in a name for the data: 
Set /p arg2=Type in the directory of the project: 
Set /p arg3=Type in the programming language : 
Set /p arg4=Type in a version for the metric data: 
+0

現在我幾乎不回答了? – Trigger