@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%这是我感到困惑的部分,about...not非常确定如何将变量从powershell设置为.bat文件中的一个变量。
FOR /F "usebackq delims=" %%v IN ('powershell -noprofile -File C:\Users\aborgetti\Desktop\getdate.ps1') DO set "d=%%v"任何帮助都将不胜感激。
BTW
$d变量在一组名为Bluezone FTP 3.2的FTP程序的初始命令中使用
getdate.ps1看起来是这样的:
$a = Get-Date
$b = $a.ToString('MMddyy')
write-host $b发布于 2014-05-12 20:46:59
powershell脚本需要输出值,而不是存储在变量中。两个不同的解决方案(未经测试),灵感来自于@zdan's answer在一个不同的问题中的灵感:
FOR /F "usebackq delims=" %%v IN (`powershell -noprofile "& { (get-date).ToString('MMddyy') }"`) DO set "d=%%v"或者:
getdate.ps1:
$a = Get-Date
$b = $a.ToString('MMddyy')
$b批处理:
FOR /F "usebackq delims=" %%v IN (`powershell -noprofile -File "C:\Users\ab\Desktop\getdate.ps1"`) DO set "d=%%v"https://stackoverflow.com/questions/23618016
复制相似问题