question

herschel-0006 avatar image
0 Votes"
herschel-0006 asked MotoX80 answered

simple script can execute on win 10 and server 2019 but not win 11 and server 2022

Want to write a script that add current date on file name and cut to another folder, but can execute on win 10 and server 2019 but not win 11 and server 2022. How can I solve it?

 cd E:\FGT_temp
 E:
    
 @set name=%date:10,4%%date:4,2%%date:~7,2%
    
 ren Richlands.conf "%date:-4,4%%date:-7,2%%date:-10,2%Richlands.conf"
 ren Manurewa.conf "Manurewa_%date:-4,4%%date:-7,2%%date:-10,2%.conf"
    
 md "E:\FGT_backup%name%"
    
 xcopy /s "E:\FGT_temp" "E:\FGT_backup%name%"
 del /s /Q E:\FGT_temp

windows-servermicrosoft-graph-batching
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered

I don't see how that .bat file is going work correctly on any Windows version. Your date substring commands are wrong.

Save this as a test.bat file and run on all of your machines. It will verify that they all have the date set in the same format.

 @echo Here is the date variable.
 @echo %date% 
 @echo Here is the year.
 @echo %date:~10,4% 
 @echo Here is the month.
 @echo %date:~4,2% 
 @echo Here is the day.
 @echo %date:~7,2% 

It should look like this.

 C:\Temp> test.bat
 Here is the date variable.
 Sat 05/07/2022
 Here is the year.
 2022
 Here is the month.
 05
 Here is the day.
 07

Build your file names using the desired date sequence.

If some of your machines have different date formats, then I would recommend using Powershell instead of a .bat file.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.