【发布时间】:2017-11-17 00:41:16
【问题描述】:
“部署和映像工具环境”是我使用的专门运行此命令的快捷方式 - 'C:\WINDOWS\system32\cmd.exe /k "C:\Program Files (x86)\Windows Kits\10\Assessment和部署工具包\部署工具\DandISetEnv.bat" '。
我要做的是在 Powershell 脚本中运行此命令,然后在该新窗口中运行 another 命令。我需要运行的命令是oscdimg,它不能在powershell中直接运行,这个.bat文件需要先运行,然后是里面的长oscdimg。这是我当前的脚本。最后的所有 cmets 都是我已经采取的不同方法,但没有成功。我得到的最远的是启动 .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
【问题讨论】:
-
您能否提供一个简化示例来说明您正在尝试做什么?可以在任一方向传递变量,从 PowerShell 到 Batch 或从 Bach 到 PowerShell。我的评估是你有太多的变量,你遇到了逃避问题。此外,您可以将所有内容放入 powershell 脚本中,然后让脚本写出 .bat 文件并执行它。
-
查看更改后的帖子。感谢您的回复
标签: windows powershell batch-file cmd parameters