将powershell变量传递给批处理脚本

时间:2014-10-08 18:16:09

标签: powershell batch-file blat

这是powershell脚本

$a = get-date -format "MMM-d-yyyy"
Start-Process "D:\Script\send_report.bat"

send_report.bat使用blat发送电子邮件

D:
cd "D:\Program Files (x86)\blat321\full"
blat -s "Daily Report" -i "Our Team" -to member1@team.org,member2@team.org -body "Please see attached." -priority 1 -attach D:\Script\Daily_Report.xlsx

如何将$a插入send_report.bat?我希望“每日报告”旁边的$a价值

2 个答案:

答案 0 :(得分:3)

在PowerShell脚本中,将$a作为参数添加到批处理文件中:

Start-Process "D:\Script\send_report.bat" $a

在批处理文件中,将参数引用为%1

blat -s "Daily Report %1" -i "Our Team" -to member1@team.org,member2@team.org -body "Please see attached." -priority 1 -attach D:\Script\Daily_Report.xlsx

答案 1 :(得分:3)

@echo off
cd /d "D:\Program Files (x86)\blat321\full"
set "the_date=%~1"
blat -s "Daily Report" -i "Our Team" -to member1@team.org,member2@team.org -body "Please see attached." -priority 1 -attach D:\Script\Daily_Report_%the_date%.xlsx

并像蝙蝠一样打电话:

$a = get-date -format "MMM-d-yyyy"
Start-Process "D:\Script\send_report.bat" $a