Get Back or Retrieve your Intune PowerShell Scripts
In this article, we will show you how to retrieve your Intune PowerShell scripts. You can get your PowerShell scripts deployed via Intune back in case the original scripts are accidentally deleted.
In our previous guide, we covered the steps to deploy PowerShell scripts using Intune. You can use the Microsoft Intune management extension to upload PowerShell scripts to Intune and then assign the scripts to Windows 10 and Windows 11 devices. For example, you can use PowerShell script to deploy fonts on Windows devices.
In the Intune admin center, when you upload a PowerShell script for deployment, you cannot download it back. Frankly speaking, the Intune admin center doesn’t provide an option to download the PowerShell scripts once they have been uploaded. But what if you need to get this original PS script back? The good news is that you can download all of your device management PowerShell scripts from Intune using multiple methods. Let’s see how.
Also See: How to Run Shell Scripts on macOS devices in Intune
The need to get back your Intune PowerShell scripts
Let us say that you or a team member have uploaded some crucial PowerShell scripts to Intune for deployment from your PC. The uploaded scripts are now deleted from your local computer, assuming they are no longer needed in the future. What if you need the scripts to import them to another tenant, and they have been deleted? How do you get them back from Intune?
The scenario that we described above is common in most organizations that use Intune to distribute PowerShell scripts to Windows devices. The assigned scripts are not documented, which causes additional issues when you require them back. When you have multiple Intune admins working on PowerShell script deployment, chances are that a PowerShell script may be accidentally deleted from the laptop.
Also Read: Deploy Fonts using Intune: 3 Proven Methods
Ways to retrieve PowerShell Scripts Deployed via Intune
There are two ways to get back your PowerShell scripts that you have deployed in Intune:
- Download uploaded Intune PowerShell Scripts using Microsoft Graph
- Use a PowerShell script to retrieve the uploaded scripts to Intune
We believe that, of the two methods described above, using a PowerShell script can help you easily retrieve all of your uploaded scripts to Intune. Using Microsoft Graph to retrieve your Intune PowerShell scripts requires expertise, and it’s a complex method as compared to using a script.
Location of PowerShell Scripts in Intune
The PowerShell scripts that you have uploaded to Intune can be located using the following steps:
- Sign in to the Microsoft Intune Admin Center.
- Select Devices > Windows > Scripts.
- Switch to the Platform Scripts tab to find all the uploaded PowerShell scripts in Intune.
Location of Intune PowerShell Scripts on Target Devices
When you deploy PowerShell scripts to your Windows devices using Intune, the scripts are downloaded to the following location: C:\Program Files (x86)\Microsoft Intune Management Extension\Policies\Scripts.
Remember that after the PowerShell scripts are downloaded to the target devices, you need to be quick to retrieve them. That’s because the PowerShell scripts stay in this location for a very short time. Once the PS deployment is complete, the Intune management extension deletes those scripts.
Retrieve your Intune PowerShell Scripts
In this step, we will show you how to retrieve your Intune PowerShell scripts. To achieve this, we will use the Get-DeviceManagementScripts.ps1 script written by my friend Oliver Kieselbach, who is an Enterprise Mobility MVP. We thank him for this fantastic script, which allows many Intune administrators and consultants to retrieve PowerShell scripts from Intune.
Note: There are numerous scripts available on GitHub that can help retrieve PowerShell scripts deployed via Intune. We have tested several scripts and found Oliver Kieselbach’s PS script worked flawlessly.
Step 1: Download Get-DeviceManagementScripts.ps1 from GitHub
The Get-DeviceManagementScripts.ps1 gets your uploaded Intune PowerShell scripts downloaded to a folder. The script is straightforward to use, and it downloads the uploaded scripts from Intune to a folder on your device. Use the following link to download Get-DeviceManagementScripts.ps1 from GitHub.
Step 2: Run the Get-DeviceManagementScripts PowerShell Script
The Get-DeviceManagementScripts cmdlet downloads all or individual PowerShell scripts from Intune to a specified folder. To run this script, launch PowerShell as an administrator. Change the path to the location of the script, and now call the PS script.
When you run Get-DeviceManagementScripts.ps1, it uses the Intune PowerShell SDK, which provides support for the Intune API through Microsoft Graph. You’ll have to authenticate with an account to retrieve your Intune PowerShell scripts.
The above script runs and downloads all the PowerShell scripts from Intune and saves them to the C:\Temp folder. All the PowerShell scripts that were previously uploaded to Intune were successfully retrieved, as shown in the screenshot below.
The Get-DeviceManagementScripts script offers two options for you: you can run the script to get all your Intune PowerShell scripts to a specific folder or download an individual PowerShell script to the specified folder.
Run the following command to retrieve your Intune PowerShell scripts to the specified folder:
Get-DeviceManagementScripts -FolderPath C:\temp
Run the below PS command to download an individual PowerShell script to the specified folder. If you are using this command, you must enter the name of the script that you want to download.
Get-DeviceManagementScripts -FolderPath C:\temp -FileName myScript.ps1