2011-07-07 34 views
4

現在、以下はVMware vSphere PowerCLIコマンドプロンプトを起動するためのパスです。 sample.ps1スクリプトをバッチファイルを使用して自動的に実行したいと思います。 sample.ps1をこのパスに組み込み、バッチファイルを作成するにはどうすればよいですか?あなたはPowerShellの2.0を使用している場合バッチファイル(.bat)を使用したPS1スクリプトの実行

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -c ". \"C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\"" 
+0

あなたが何を求めていますか?上記のように、powershell.exeを実行するだけで、cmdスクリプトからいつでもpowershellスクリプトを呼び出すことができます。他に何をしようとしていますか? –

+0

-psc = -PSConsoleFile - コンソールファイルを読み込んで、SNAPINを自動的にインポートします。 -noe = -NoExit - >を実行して、powershellセッションを維持します。彼が立ち上げたいスクリプト。 – JPBlanc

+0

これは複製ではありません... http://stackoverflow.com/questions/6037146/how-to-execute-powershell-commands-from-a-batch-file – SteveC

答えて

3

、あなたはPowerShellの1.0を使用している場合、あなたはこのよう

を使用-commandパラメータができたpowershell.exe

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -file "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1" 

-fileパラメータを使用することができます

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -command "& 'C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'" 
+0

助けてくれてありがとう。 – dwyane

1
echo off 

Title,Report Script &color 9e 
for /f "usebackq delims=$" %%a in (`cd`) do (
    set SCRIPTDIR=%%a 
) 

(Set ScriptFile=%SCRIPTDIR%\Report.ps1) 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -c ". \"C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\";%ScriptFile%" 
0

あなたはバットを呼び出すことによって、.BATファイルを経由して、任意の.ps1スクリプトを起動するためにこれを使用することができますあなたのps1のようなファイル。次に、バッチでファイルの名前を抽出し、それを使ってpowershellを呼び出します。ソリューションを使用する準備のために

、以下の要旨を使用します。https://gist.github.com/JonasGroeger/10417237

0

を、私は別のページにこのコードを見て、私はW2012 R2でそれをテストし、それが実行されます。

私はそれを動作願っています:

C:\>powershell "C:\>1\file.ps1" 
関連する問題