If you manage a modern workplace, you’ve likely encountered a strange limitation in the Microsoft Intune Admin Center: once you upload a PowerShell script, there is no “Download” or “View” button to get it back.
Whether you need to audit old code, migrate to a new tenant, or simply lost your local copy, recovering these scripts is a common challenge for IT Admins. In this guide, we’ll show you how to use the Microsoft Graph API to pull your scripts back down to earth.
Why is there no “Download” button in Intune?
Microsoft treats Intune as a deployment engine rather than a script repository. When you upload a .ps1 file, Intune converts the text into a Base64 encoded string and stores it in the service. While the portal shows you the script’s name and assignment status, the underlying code is hidden from the UI to keep the interface clean and focus on management rather than development.
Prerequisites: What you need before starting
Before you can run the export process, ensure you have the following:
- Permissions: You must have the Intune Administrator or Global Administrator role.
- PowerShell Module: You need the Microsoft Graph SDK installed. You can install it by running:
Install-Module Microsoft.Graph -Scope CurrentUser - A Local Folder: Create a folder (e.g.,
C:\IntuneScripts) where you want the exported files to land.
The PowerShell Export Script
Copy the following script into your PowerShell ISE or VS Code. This script automates the retrieval and decoding process for every script in your tenant.
PowerShell
Step 1: Connecting to Microsoft Graph
The script uses Connect-MgGraph with the DeviceManagementScripts.Read.All scope. This is the “key” that opens the Intune script vault. When you run this, a browser window will open asking you to sign in and “Consent on behalf of your organization.”
Step 2: Decoding Base64 Script Content
The API returns your code in a format called Base64. To make it readable, the script takes that string, converts it back into a byte array, and finally translates it into standard UTF8 text before saving it as a .ps1 file.
Exporting Remediation Scripts
Remediation scripts are stored differently than standard scripts because they come in pairs (a Detection script and a Remediation script). To export these, you change the API endpoint to deviceHealthScripts.
The Updated Script Snippet:
PowerShell
Troubleshooting “403 Forbidden” Errors
If you run the script and see a red 403 Forbidden error, it usually means your session doesn’t have the right permissions.
- The Fix: Run
Disconnect-MgGraphand then run theConnect-MgGraphcommand from the script again. - Check Scopes: Ensure you are using the specific scope
DeviceManagementScripts.Read.All. Without this exact permission, the Graph API will block the request even if you are a Global Admin.
Conclusion
While the missing download button in Intune is a hurdle, the Microsoft Graph API makes it possible to manage your scripts programmatically. By using this export script, you can ensure your hard-coded logic is always backed up and available for review.




