2017-06-14 614 views
0

“部署和映像工具环境”是我使用的专门运行此命令的快捷方式 - 'C:\ WINDOWS \ system32 \ cmd.exe/k“C:\ Program Files x86)\ Windows Kits \ 10 \ Assessment and Deployment Kit \ Deployment Tools \ DandISetEnv.bat“'。从Powershell脚本运行带参数的.bat文件

我想要做的是在Powershell脚本中运行此命令,然后在该新窗口中运行另一个命令。我需要运行的命令是oscdimg,它不能直接在PowerShell中运行,这个.bat文件需要先运行,然后再运行那个很长的oscdimg。这是我目前的脚本。最后所有的评论都是我已经采取的不同方法,但没有成功。我得到的最远距离是启动.bat文件,但通过我认为通过了不正确的参数。感谢您的帮助

根据要求,Here是我想要做的更简单的例子。这个小脚本运行cmd,并尝试添加参数以更改目录,但生成的cmd窗口不会这样做。

$srcDIR = Read-Host -Prompt 'Paste the Source Files Directory ' 
$destDIR = Read-Host -Prompt 'Paste the output destination, with .iso extension ' 

$etfsbootDIR = "$srcDIR\boot\etfsboot.com" 
$efisysDIR = "$srcDIR\efi\microsoft\boot\efisys.bin" 

$etfsboot = "`"" + $etfsbootDIR + "`"" 
$efisys = "`"" + $efisysDIR + "`"" 
$src = "`"" + $srcDIR + "`"" 
$dest = "`"" + $destDIR + "`"" 

$dir8 = "C:\Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg" 
$dir10 = "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg" 

if(Test-Path $dir8) { 
    # cd $dir8 
    $etftest = $dir8 + "\etfsboot.com" 
} 
elseif(Test-Path $dir10){ 
    # cd $dir10 
    $etftest = $dir10 + "\etfsboot.com" 
} 
else{ 
    "No Assessment and Deployment Kit detected." 
    return 
} 

$etft = "`"" + $etftest + "`"" 

if(Test-Path $etfsbootDIR) { "etfsboot.com found at $etfsboot" } 
if(Test-Path $efisysDIR) { "efisys.bin found at $efisys"  } 

$beginning = "./oscdimg.exe -m -o -u2 -udfver102 -bootdata:2#p0,e,b" 
$middle = "#pEF,e,b" 
$command = $beginning + $etfsboot + $middle + $efisys + " " + $src + " " + $dest 

$rest = "C:\windows\system32\cmd.exe /k 'C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat'" 
$shortcut = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Windows Kits\Windows ADK\Deployment and Imaging Tools Environment.lnk" 

# Start-Process -FilePath $shortcut -ArgumentList $command 
# cmd.exe /c $rest $command 
# cmd %1 $rest 
# & $rest $command 
+0

你可以提供你一个简单的例子'试图做什么? 可以在任一方向传递变量,从PowerShell到Batch或从Bach到PowerShell。我的评估是你有太多的变数,而你正在遇到逃避的问题。 此外,您可以将所有内容放入PowerShell脚本中,然后让脚本写出.bat文件并执行它。 – Bewc

+0

查看已更改的帖子。感谢您的回应 –

回答

0

我在参数的开头缺少a/c或/ k,所以cmd知道明显运行它。 (/ C运行参数,并关闭窗口,/ K运行它,并保持窗口打开)

工作例 -

$command = "/k cd .."

Start-Process cmd -ArgumentList $command