@echo off
Powershell.exe -executionpolicy remotesigned -File C:\Users\aborgetti\Desktop\getdate.ps1
FOR /F "usebackq delims=" %%v IN ('powershell -noprofile -File C:\Users\aborgetti\Desktop\getdate.ps1') DO set "d=%%v"
echo %d%
This is the part that I am confused about...not really sure how to set the variable from powershell to a variable in the .bat file.
FOR /F "usebackq delims=" %%v IN ('powershell -noprofile -File C:\Users\aborgetti\Desktop\getdate.ps1') DO set "d=%%v"
Any help would be much appreciated.
BTW
The $d variable is being used in a set of initial commands for an FTP program called Bluezone FTP 3.2
getdate.ps1 looks like this:
$a = Get-Date
$b = $a.ToString('MMddyy')
write-host $b
Your powershell script needs to output the value, not store it in a variable. Two different solutions(untested), inspired by @zdan's answer in a differen SO question:
FOR /F "usebackq delims=" %%v IN (`powershell -noprofile "& { (get-date).ToString('MMddyy') }"`) DO set "d=%%v"
Or:
getdate.ps1:
$a = Get-Date
$b = $a.ToString('MMddyy')
$b
Batch:
FOR /F "usebackq delims=" %%v IN (`powershell -noprofile -File "C:\Users\ab\Desktop\getdate.ps1"`) DO set "d=%%v"
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.