首页 > 解决方案 > 批处理脚本中的多行powershell函数

问题描述

我想运行.bat-script 在其中调用一些 powershell 函数。功能不是那么小,所以我想拆分它。但我做不到,转义符号无济于事(`,^)。脚本示例:

set file=%1

set function="$file=$Env:file; ^
              $hash = CertUtil -hashfile $file SHA256 | Select -Index 1"

powershell -command %function%

标签: powershellbatch-file

解决方案


您可以将引号留在每行的末尾,如下所示:

set file=%1

set function="$file=$Env:file; "^
           "$hash = CertUtil -hashfile $file SHA256 | Select -Index 1; "^
           "example break line further...."

powershell -command %function%

作为^多行字符工作,但它也会转义第一个字符,因此也会转义引号。


推荐阅读