将批处理文件中的变量值发送到 Powershell 脚本

将批处理文件中的变量值发送到 Powershell 脚本

如何将变量的值从批处理传递到 powershell?

我正在尝试使用此链接中的命令:
https://stackoverflow.com/questions/6359618/pass-parameter-from-a-batch-file-to-a-powershell-script

链接中传递的是字符串,那也可以传递变量吗?

批处理文件中使用的命令:

powershell.exe -executionpolicy remotesigned -File "C:\Users\%username%\Desktop\Normalize_LUFS\LUFS.ps1 %vLUF%"

在Powershell脚本启动时设置参数:

$sw = $args[0]

$logMatches = Select-String -Path "C:\Users\$env:username\Desktop\Logs_LUFS\*.log" -Pattern '(?<I>^ +I:) +(?<LUFS>.+)|
(?<I>^Input Integrated:) +(?<LUFS>.+)' -List Out-File "C:\Users\$env:username\Desktop\Logs_LUFS\List.txt"

$sw 变量是否会从批处理文件的 vLUF 变量接收值?

答案1

工作原理如下:

在批处理文件中:

powershell.exe -executionpolicy remotesigned -File C:\Users\%username%\Desktop\Normaliza_LUFS\ArqsVolAbaixo_LUFS_informado.ps1 %vLUF%

在 Powershell 脚本开始时设置参数:

Param(
     [decimal]$env:vLUF
)

[decimal]$vLUFps = $env:vLUF

相关内容