MDT: Run a PowerShell script as an application

In this tutorial, we’ll see how to run a PowerShell script with MDT By adding it as an application, this solution will allow the script to be executed on demand during deployment by selecting it from the list of applications or by putting it directly into the task sequence.

This method is more flexible than the one I presented to you previously: MDT: Run a PowerShell script during a deployment

Prepare the application with the PowerShell script

To begin, we will prepare our application, which we want to add to MDT, which will contain our PowerShell script.

Create a folder named after the application in the location where you keep your source code, then create two other files inside that folder:

  • The PowerShell script script: script.ps1
  • A batch file that will execute the ps1 file: setup.bat

Which gives us:

In the file script.ps1 write or paste the contents of the PowerShell script you want to run.

For the file setup.batThe content is as follows:

powershell.exe -ExecutionPolicy Bypass -File "script.ps1"

As you can see, we are using the file setup.bat to execute the PowerShell file by specifying several parameters, including the file name ps1.

Add the application to MDT

Now that we have the PowerShell script, we will add the application to MDT.

From the MDT console, go to the Applications 1 folder of Deployment Share and click on New Application 2.

When launching the application addition wizard in MDT, select Application with source files 1 and then click the Next button 2.

Name the application 1 and click on Next 2.

Specify the source folder 1 which contains the files and click on the Next 2 button.

Leave the folder as default, click on Next 1.

In the Command line field, enter the name of the batch file (setup.bat) 1 and click on Next 2.

Validate the application information and then click Next 1 to add it to MDT.

Once the application import into MDT is complete, click on Finish 1 to close the wizard.

The application has been added to MDT:

Run the PowerShell script as an application with MDT

To install an application with MDT, in our case, run the PowerShell script, you have several solutions which you can find in the various tutorials available on the site.

I will still give you a reminder in this one:

Select the application during the deployment wizard

When choosing which applications to install, select the application from the list.

The script will be executed if the application is selected.

Add the application to the task sequence

To force the execution of the application and therefore the script, one solution is to add the application directly into the task sequence.

In the task sequence properties, copy/paste “Install application” by right-clicking on it.

Once copied, rename the task 1, select Install a single application 2 then click on the Browse button 3.

Select application 1 then click OK 2.

Then click the Apply and OK buttons to save the changes to the task sequence.


You now know how to easily run PowerShell scripts on MDT during your Windows deployments.

Romain Drouche
System Architect | MCSE: Core Infrastructure
IT infrastructure expert with over 15 years of field experience. Currently a Systems and Networks Project Manager and Information Systems Security (ISS) expert, I use my expertise to ensure the reliability and security of technological environments.

Leave a Comment