Deploy Files Anywhere Using Intune and Powershell

How do I deploy a folder to users using Intune?

I came across a scenario where I needed to deploy a folder full of PDF files for a set of users, and the folder needed to be available to all users via the Public Desktop.They needed to be deployed using Intune, since the devices are 100% cloud managed.

We can achieve this by packaging our files/folder and powershell script into a Win32 application and deploying it through Intune.

  • Create a single folder that we will use to package all the files and scripts with. I created C:\Intune\Package. This directory will hold the folder I want to deploy: Folder1. This folder has a few PDF files in it (ex. one.pdf, two.pdf, etc.). Folder1 should be located at C:\Intune\Package\Folder1.

  • Create a PowerShell script and name it DeployFiles.ps1. Put it at C:\Intune\Package\DeployFiles.ps1

Here's the contents of the script:

 1# Change this to the name of the folder you are deploying
 2$Folder = "Folder1"
 4# Parent directory of the current script being executed (ex. C:\Intune\Package)
 5$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition 
 7# This is the folder you are deploying,
 8# make sure it is located inside of the
 9# parent directory of the script.
10$Source = "$PSScriptRoot\$Folder"
12# $Destination is the directory that the files/folder will be deployed to
13$Destination = "C:\Users\Public\Desktop\"
15# Move the $Folder and contents within it to the $Destination 
16Copy-Item -Path $Source -Destination $Destination -Recurse -Force #-whatif

Now that the PowerShell script is done, we need to create an install command for Intune so it knows to run the script.

  • Create a cmd script file and name it deploy.cmd. Put it at C:\Intune\Package\deploy.cmd

Here are the contents of deploy.cmd:

1SET WorkingDir=%cd%
2SET PSPath='%WorkingDir%\DeployFiles.ps1'
3PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& %PSPath%"

You should now have 3 sets of files:

  1. C:\Intune\Package\Folder1 - The files to deploy
  2. C:\Intune\Package\DeployFiles.ps1 - The PowerShell to Copy-Item the files to the $Destination
  3. C:\Intune\Package\deploy.cmd - The install command that Intune will run

Now that we have everything ready to deploy, we need to package the contents of C:\Intune\Package into a .intunewin file that we can upload as a Win32 app to Intune.

Use the Microsoft Win32 Content Prep Tool to package the files into a file.intunewin format.

Once you have your file.intunewin prepared, navigate to Intune, go to Apps -> Windows -> Press Add and select the App type Windows app (Win32). Upload the file.intunewin you created when you select the app package file.

Now configure your app, here's what I did:

  1. Give the application a Name, Description, and Publisher. Go to next page.

  2. Set the Install command to deploy.cmd, set the Uninstall command to exit. Go to next page.

  3. Set the Operating system architecture and Minimum operating system to whatever values are applicable to your environment. Go to next page

  4. Set the Rules format to Manually configure detection rules,

    • set the Rule type to File,
    • set the Path value to the same value/directory as the $Destination variable in the PowerShell script (ex. C:\Users\Public\Desktop),
    • set the File or folder value to the name of the file or folder (ex. Folder1),
    • set the Detection method value to File or folder exists,
    • set the Associated with a 32-bit app on 64-bit clients value to No.
    • Press OK and go to next page
  5. Apply your Win32 app to Groups of users or devices that you want the app to be deployed to.

  6. Review your settings and save your app. Once saved, Intune will begin to push the files out to users as if it was any Win32 application.