简体   繁体   中英

Pass powershell variable to batch script

Here is powershell script

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

send_report.bat uses blat to send email

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

How do I insert $a into send_report.bat? I would like value of $a next to "Daily Report"

In your PowerShell script, add $a as a parameter to the batch file:

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

In you batch file reference the parameter as %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
@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

and call the bat like :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM