【发布时间】:2020-06-18 11:05:51
【问题描述】:
我有以下参数设置,并尝试将其传递到 7zip 密码中,如脚本所示。我设置参数的原因是我需要传递包含当前月份和其余密码的密码。
脚本
$Password = $MonthFull+$year+"#Test"
Start-job -scriptblock {
param($p_output_zip_file, $p_exported_files)
Set-Alias SZ "C:\Program Files\7-Zip\7z.exe"
**SZ a $p_output_zip_file $p_exported_files -sdel -p'Jun2020#Test'** -- I need this to pick up the current month plus the rest of the password
} -name "Compress_File" -ArgumentList "$output_zip_file","$exported_files" | Out-Null
谢谢
【问题讨论】:
-
'Jun2020#Test'-->('{0:MMMyyyy}{1}' -f (Get-Date), '#Test') -
谢谢你,我可以看到这将设置我想要的密码,但是 7zip 在解压时返回错误的密码。
-
您可能需要用单引号将构造的密码括起来(就像您对硬编码示例所做的那样)。现在无法测试,因为我在移动设备上。
-
这修复了它 $('-p' + ('{0:MMMyyyy}{1}' -f (Get-Date), '#Test'))
标签: bash powershell shell parameters 7zip