You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在批处理文件中换行编写PowerShell命令的方法咨询

我正在批处理(.bat)文件中执行PowerShell脚本,为提升代码可读性,希望将命令拆分为多行编写。在PowerShell中可使用`符号实现换行,但该符号在批处理文件中无法生效。我需要拆分的命令如下:

powershell -Executionpolicy ByPass -NoProfile -Command "Import-Csv .\outfit-verfuegbarkeit-temp.csv -delimiter ';' | ForEach-Object {if ($_.Inventory -like 'New') {$_.Inventory = '0'} $_} | Export-Csv .\outfit-verfuegbarkeit-temp2.csv -delimiter ';' -NoTypeInformation"

请问批处理文件中用于忽略换行的字符是什么?

解决方案

批处理文件中用于忽略换行、将多行命令视为一行执行的字符是脱字符^,使用时需注意两个关键点:

  • ^必须是每行的最后一个字符,后面不能附带空格或其他字符
  • 要保证PowerShell命令的双引号始终配对,避免语法错误

拆分后的批处理命令示例:

powershell -Executionpolicy ByPass -NoProfile -Command ^
"Import-Csv .\outfit-verfuegbarkeit-temp.csv -delimiter ';' ^
| ForEach-Object {if ($_.Inventory -like 'New') {$_.Inventory = '0'} $_} ^
| Export-Csv .\outfit-verfuegbarkeit-temp2.csv -delimiter ';' -NoTypeInformation"

此示例中无需额外转义其他字符,直接用^拆分即可实现多行排版且不影响命令执行。


内容的提问来源于stack exchange,提问作者Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 11:47:33