Why ?
If
you intended to use a PowerShell functions and code to retrieve certain output
or do some work using PowerShell scripting instead of CMD and accordingly you
will complete your work in CMD batch scripting , in this case I am sharing a
simple code to achieve this.
How ?
Below
is a sample code script running as .bat , CMD batch scripting that will call PowerShell
script to retrieve yesterday date and store it in CMD batch variable and continue
work with it in CMD , retrieving yesterday date is very difficult in CMD however
it is so easy on PowerShell thus I use it as below:
1- Code below, please save it in .bat and run it
using CMD:
for /f "delims="
%%a in ('powershell get-date((get-date^).addDays(-1^)^) -uformat
"%%Y%%m%%d"') do set date=%%a
for /f "delims="
%%a in ('powershell get-date((get-date^).addDays(-1^)^) -uformat
"%%Y%%b%%d"') do set date2=%%a
echo %date%
echo %date2%
::echo %datetime%
set year=%date:~0,4%
set mm=%date:~4,2%
set day=%date:~6,2%
set mmm=%date2:~4,3%
echo checking files for
date %year%/%mm%/%day% %time%
echo checking files for
date %year%/%mmm%/%day% %time%
pause
No comments:
Post a Comment