MDT – Add deployment information with PowerShell and perform a REFRESH scenario

Hi, just a quick post about an idea I wanted to share with you all:

A request from a colleague -since we are using MDT to deploy our corporate machines- was to create a mechanism that prevents the re-partitioning and formatting of hard drives that have already been deployed with MDT.

Now this can easily be done by creating the following steps in your deployment task sequence:

figure 1.1: Set Task Sequence Variable – DeploymentType


As you can see above, the Task Sequence Variable “DeploymentType” will be set, during the execution of the task sequence. But how can we achieve this only happens if for example the machine has already been installed with MDT a previous time?

figure 1.2: Task Sequence Variable Condition


By setting a condition on this Task Sequence Variable. For example by checking if a certain file exists. Naturally it is key, that this file will be created at the first initial deployment of the machine, or the file is created manually afterwards. The reason why I check both C: and D: drive, is that within Windows PE, it may occur that sometimes your C: drive is detected as D: drive due to the “System Reserved” or “System” partition.

This way I’m always right.

Now, to generate a file for identification, I’ve created a powershell script, which dumps certain Task Sequence Variables queried by the ZTIGather.wsf script in a text file, together with a couple of WMI queries:

The script is pretty straight forward:

First it sets the invocation path, which is the path from where the script is called. Then it sets the variables which are needed as input for the script. And the cool thing is, since ZTIGather.wsf queries the entire machine, we can use the MDT Task Sequence Variables as input for our script, which will be dumped into the text file.

To determine the computername, I wanted to use the OSDComputerName task sequence variable, but strangely enough, it outputted the AssetTag instead, for this reason I used the WMI query:

And the same thing goes for the Windows Operating Sytem version:

And bitlocker recovery key:

I then just needed to format these results in a readable usable manner, to get all my variables straight.

Now that’s out of the way, I needed a folder to store this information in, but I don’t want to bother end-users looking into it. So I create a folder called “MDTRollout” and placed it in the root of C:\ and give it the “Hidden” attribute, also I perform a check if the folder itself does not exist, in that case it will be created.

The same thing goes for the text file which is automatically created, if it does not exist. And if the file exists, it will add the content, for example when the machine is reïnstalled for the 2nd, 3rd, or 50th time.

And now to show you the result:

figure 1.3: No folder present at first


figure 1.4: running the script


figure 1.5: Task Sequence has finished


figure 1.7: Contents of the DeploymentInfo.txt004

There you have it, a little usefull file which can be used to quickly evaluate the computer’s identity and configuration. Which on it’s turn, forms the basis to perform a MDT REFRESH scenario, instead of a NEWCOMPUTER scenario.

The script can be placed in the .\DeploymentShare\Scripts folder, and executed with a “Run Powershell Script” step from within the Task Sequence properties pane. You can call the script as following: “%Scriptroot%\MDT_DeploymentInfo.ps1”, the great thing about doing it this way, is that MDT handles the execution policy of powershell which would otherwise prevent the execution of the script. Normally it is necessary to set the policy to “Bypass” or “Unrestricted”.

figure 1.8: Calling the script


figure 1.9: Testing it yourself


Now to test the script yourself, a custom task sequence with the following two steps should do the trick:

  1. “Gather”
  2. “Run PowerShell Script”

Hope this can be of use to anyone else.

Find attached the screenshots used, and the actual script, which can be downloaded


Cheers and have great 2014/2015! Merry Christmas and a Happy New Year!!!!

8 thoughts on “MDT – Add deployment information with PowerShell and perform a REFRESH scenario

  1. Alexandr

    And one more question. I interrupted the problem with refresh computer.I wrote the feedback on
    The main problem is after restart computer TS doesnt continue, instead the last step is
    Property PHASE is now = PREINSTALL
    ZTINextPhase COMPLETED. Return Value = 0
    Event 41001 sent: ZTINextPhase processing completed successfully.
    Run Command: X:\windows\system32\bcdedit.exe /delete {d22e7e91-9ee7-46eb-89d7-c5859e4302f0} /cleanup
    BCD> The operation completed successfully.
    BCDEdit returned ErrorLevel = 0
    Removing BCDEdit
    Removing AutoAdminLogon registry entries
    VSSMaxSize not specified using 5% of volume.
    Logs contained 0 errors and 0 warnings.
    Checking mapped network drive.
    testing drive Z: mapped to \\mdt\DS$
    Disconnecting drive Z: mapped to \\mdt\DS$
    Cleaning up C:\MININT directory.
    Cleaning up TOOLS, SCRIPTS, and PACKAGES directories.
    Removing C:\MININT folder (final log entry)

    The mystery is on another linked deployment share all works like a charm. No any problem.
    I can send you full log. And video with problem.
    Thank you for your answer.

    1. Alexandr

      The problem was solved.

      I am make mistake previously. And tested some new features, I icluded file Unnattend.xml to extrafolder


      Lite Touch PE
      wscript.exe X:\Deploy\Scripts\LiteTouch.wsf

      wscript.exe X:\Deploy\Scripts\LTICleanup.wsf

      This file execute LTICleanup scenario.

  2. RoyF

    Great script Rens, found 1 typo, missing “a” in Enabled 😉

    $BDE = “Bitlocker Enbled

    Should be :

    $BDE = “Bitlocker Enabled:

  3. Khalfe

    Hi Rens;
    This blog is verry interesting, I have some difficults I’m working in a script who set the bios configuration while installing windows 7 or 10 by MDT, then my first question is:
    Wich variable I can use to identify the os of the new task sequence I mean the current os the mdt preparing to install in the computer after the user select the os during the installation.
    I’m wondering if this code doying the job
    $OS = Get-ChildItem -Path $OSPath | Out-GridView -PassThru -Title “Select required OperatingSystem”
    $OSPath = “$($MdtDrive):\Operating Systems”



Leave a Reply

Your email address will not be published. Required fields are marked *