Earlier this year I wrote an article for REDMOND Magazine about the new backup features in Windows Server 2008 R2. I’m not going to re-hash the article here except to say it includes some sample scripts on using the WBADMIN command line tool. One of the scripts is an old-school batch file.

The batch file included code to create a directory that included a time stamp, like \\mycompany-dc01\backup\RESEARCHDC\12152009_132532 where the last portion is the month, day, year, hour, minute and second. My original code parsed out these values from the %TIME% variable.

Unfortunately, I forgot to take into account situations where the time mght not have two digits like 1:00AM. In those situations the code tries to create a folder like \\mycompany-dc01\backup\RESEARCHDC\12152009_ 10000 which fails because of the space. To correct this I needed to add a line to check for the space in the variable, %h% and if found, define a new value with a leading 0.

This sort of thing is much, much easier in Windows PowerShell, by the way. But regardless, I now have an updated batch file.
[cc lang=”DOS”]

You can download the batch file here. Rename it to .bat.