How can I get the current date? RRS feed

  • Question

  • I'd like to set a task sequence variable (BackupFile) to a name using the current date. I am using the Set Task Sequence Variable step in my task sequence, how can I set it to be something like, Win7-09-28-13.wim? Thanks.
    Wednesday, November 6, 2013 11:03 PM

All replies

  • Use:

    BackupFile=Win7-_#month(date) & “-” & day(date) & “-” & year(date)#.wim

    Wednesday, November 6, 2013 11:29 PM
  • Use:

    BackupFile=Win7-_#month(date) & “-” & day(date) & “-” & year(date)#.wim

    I did this but I would get an error creating WIM file. Checking BDD.log showing imagex was executing with the command imagex /capture /compress maximum c: Win7-_#month(date) & “-” & day(date) & “-” & year(date)#.wim, so I assumed this was causing the error because imagex is running the command literally.
    • Edited by in2jars Thursday, November 7, 2013 12:02 AM
    Thursday, November 7, 2013 12:01 AM
  • I'm thinking I can create a custom property and set it using a UserExit script, but I'm really hoping there is a simpler way. Any other ideas?
    Thursday, November 7, 2013 4:18 PM
  • I use:


    It gives me w7x86_5-15-2013_09-18.wim. I added the time because multiple captures on the same day would collide.

    I set it in the MDT database, but I'm sure it would work in customsettings.ini

    I documented that previously here:


    • Edited by JoeZeppy Thursday, November 7, 2013 8:21 PM
    Thursday, November 7, 2013 8:19 PM
  • I'm not trying to set this in customsettings.ini which I think is the problem. Otherwise I would just do BackupFile=Win7-_#month(date) & “-” & day(date) & “-” & year(date)#.wim.

    I need to do it as a Set Task Sequence Variable task, but it appears that doing it as a task does not properly resolve the date.

    Thursday, November 7, 2013 8:21 PM
  • You can add a step to your capture TS (or capture section) to set the name automatically.

    Powershell script would look something like:

    $strDate = Get-Date -format MMyyyy

    $TSEnv:BackupFile = "WIN7E" + "_" + $strDate + ".wim"

    Save the script as BackupWIM.ps1 and run it at some point before the reboot to capture the image. To do that, you'd just need to insert a Run Powershell Script step and make sure the script is accessible. (Probably easiest to put it in the Server\Share\Scripts folder.)

    -Nick O.

    • Edited by Nick Ourso Thursday, November 7, 2013 10:18 PM
    • Proposed as answer by Keith GarnerMVP Friday, November 8, 2013 6:38 AM
    Thursday, November 7, 2013 10:18 PM