In this step-by-step guide, we will demonstrate the steps to deploy a batch file using Intune. A batch file must first be converted to .intunewin format and then deployed as a Win32 application. As an example, we will perform a sample batch file deployment with Intune on Windows 10/11 devices.
A batch file is basically a script that contains multiple commands that run in sequence to perform various actions with the Command Prompt. A batch file has a “.bat” extension, and it can be opened with the Notepad application. For example, a batch file can be used to clean old IIS logs, clear temporary files, and perform other administrative functions.
In our previous article, we discussed how to deploy a PowerShell script using Intune. Similarly, Intune allows you to deploy a batch file to Windows devices with a few simple steps. If you already distribute a batch file through GPO or another method in your organization, you can use the Microsoft Intune management extension to upload the file to Intune and deploy it to Windows devices.
Take a look at some useful app deployment guides with Intune.
- Deploy Win32 Apps with Intune
- Add iOS Store Apps to Microsoft Intune
- Deploy PKG Apps using Intune on macOS Devices
The prerequisites for deploying a batch file in Intune are as follows:
- You must use devices running Windows 10 1709 or later.
- The Windows devices must be Azure AD-joined devices or hybrid Azure AD-joined devices.
- The Windows devices must be enrolled in Intune.
- Batch file deployment via Intune also works on co-managed devices.
Steps to Deploy a Batch File using Intune
Deploying a batch file with Intune requires some basic steps, which we will go through now. Make sure the batch file is tested and ready for deployment and that the Windows devices are already registered in Intune.
Step 1: Create a batch file
You must have a batch file ready to deploy it with Intune. In this example, we will deploy the batch file “CleanSoftwareDistribution.bat” that cleans up the software distribution folder on Windows devices.
The below script cleans up the software distribution folder on Windows devices to save some disk space. Copy and paste the below code into Notepad, and save the file as CleanSoftwareDistribution.bat.
sc config wuauserv start= disabled
net stop wuauserv
PowerShell.exe Remove-Item C:\Windows\SoftwareDistribution\* -Force -Recurse
sc config wuauserv start= demand
net start wuauserv
Step 2: Convert Batch File to IntuneWin File
You cannot directly deploy a batch file (.bat) with Intune because it’s not supported. You’ll need to first convert it to an .intunewin file and deploy it as a Win32 app. In this step, we will use the Win32 content prep packaging tool and convert the batch file into the .intunewin format.
Launch the command prompt on your computer and run IntuneWinAppUtil.exe. The tool requires some basic information, which is listed below:
- Specify the source folder: The folder where the batch file is located.
- Specify the setup file: Enter the file name as CleanSoftwareDistribution.bat.
- Provide the output folder location: Specify the folder where you want the Win32 app to be created.
- Do you want to specify catalog folder: Type N
After entering the above information, the tool converts the batch file to .intunewin file. The tool also detects some of the attributes that Intune requires to determine the application’s installation state.
In the screenshot below, we see the cleansoftwaredistribution.bat file has been converted to cleansoftwaredistribution.intunewin. Now we are ready for the deployment.
INFO File 'E:\Sources\scripts\CSD\cleansoftwaredistribution.intunewin' has been generated successfully
[=================================================] 100% INFO Done!!!
Step 3: Upload the Batch File to Intune as Win32 app
Follow the below steps to upload the batch file to Intune:
- Sign in to the Microsoft Intune admin center.
- Select Apps > Windows and click on +Add.
- Click the down-drop for App Type and select the Windows app (Win32).
On the App Information tab, click on “Select app package file.” Now click on the upload icon and select the Win32 app (.bat file) to upload it to Intune. Click OK.
Like applications, when you upload a batch file to Intune, you can configure the app information and specify details about it. For example, you can specify the program name, description, publisher information, and specify a logo for the app.
Once you have specified the Win32 app details, click Next.
On the Program tab, you must specify the install and uninstall commands for the batch file deployment. Since a batch file installation occurs without any additional switches, you can input the file as the install command.
The uninstall command is something that isn’t required for a batch file (especially in our case where we are only cleaning up the files within the software distribution folder). Since Intune mandates entering the uninstall command, we have used the file name as the uninstall command.
This makes no sense, but it is only for demonstration. If you are deploying an app with a batch file, make sure to enter the correct batch file for uninstallation.
If you are going to deploy a batch file for a specific OS version and OS architecture, you can configure it on the Requirements tab.
In our case, the following OS requirements are configured for batch file deployment:
- Operating system architecture: 64-bit
- Minimum operating system: Windows 10 21H1
We have configured the following detection rules for batch file deployment with Intune:
- Rule type: File
- Path: C:\Windows
- File or folder: SoftwareDistribution
- Detection method: File or Folder exists
- Associated with a 32-bit app on 64-bit clients is configured to No.
Click OK and then select Next.
The batch file that we are deploying doesn’t rely on any other apps or require any prerequisites for it to work, so we won’t be configuring dependencies and supersedence for this deployment.
On the Assignments tab, you can assign the app as Required or Available for enrolled devices. Select an applicable device group or groups that should execute the batch file. Click Next.
On the Review+Create page, you can find a summary of all the configurations for Intune batch file deployment. If everything looks good, click Create.
The Win32 app (batch file) is now created in Intune, and you should find a notification that the Win32 app has been created successfully. Refresh the Intune admin center, and you should find the Clean Software Distribution Folder Win32 app listed under All Apps.
Step 4: Sync Intune Policies
In this step, we will manually sync our Windows devices with Intune to speed up the deployments. The Sync action forces your device to connect with Intune to get the latest updates, requirements, and communications from your organization. You can refer to the guide on how to sync Intune policies on Windows devices, which uses a variety of methods to initiate policy sync.
Step 5: Monitor Batch File deployment in Intune
After you deploy a batch file using Intune, the next step is to monitor it’s installation status. Any deployments made through Intune, whether they are Win32 apps, PS scripts, or batch files, can be monitored to see if there were any errors during installation.
To monitor the batch file deployment in Intune, use these steps:
- Sign in to the Intune admin center.
- Go to Apps > Windows, and from the list of apps, select the Win32 app (batch file).
- Select the Overview tab to see the number of devices on which the batch file installation was successful.
Troubleshooting batch file deployment with Intune
We have learned that a batch file is deployed as a Win32 app using Intune. In case your Win32 apps fail to install on Windows devices, you must troubleshoot the issues by reviewing the logs. Intunemanagementextension.log, clienthealth.log, and Agentexecutor are some basic logs that you can review during troubleshooting.
When Win32 app deployments fail, they fail with an error code. This error code is sometimes generic, and in those cases, reviewing the Intune MDM logs on client devices is critical. Whenever you encounter failures during Intune batch file deployment, we recommend reviewing Intune logs on Windows devices for troubleshooting.
We hope the steps outlined in this article help you deploy a batch file using Intune. Intune, Microsoft’s cloud-based management solution, offers a seamless way to deploy batch files to Windows devices within your organization. Many organizations still use batch files to automate tasks, and Intune can help you deploy them as a Win32 app.