How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph

In this article, we will discuss how to efficiently Backup and Restore Microsoft Intune configurations using PowerShell and Microsoft Graph. We will back up all configurations created in your Microsoft Intune tenant and store them in a shared location. Additionally, we will explore how to restore the backed-up configurations to Intune.

Microsoft Graph is an API (Application programming interface) that provides a single endpoint for accessing data, intelligence, and insights from Microsoft 365 and other Microsoft Cloud services. It provides a single endpoint, https://graph.microsoft.com, that enables access to various data and insights in the Microsoft cloud, including Microsoft 365, Windows, and Enterprise Mobility + Security.

In view of my enthusiasm towards automation, I have always found it intriguing to explore the Microsoft Graph API and PowerShell. The Graph API for Intune offers a programmatic means of accessing Intune-related information for your tenant. This Microsoft Graph API is designed to perform the same range of Intune operations as those available through the Azure Portal.

You can use the Microsoft Graph PowerShell SDK, available in the PowerShell Gallery, to automate the backup and restoration of Microsoft Intune configurations. The SDK includes two modules: Microsoft. Graph and Microsoft.Graph.Beta, which correspond to the Microsoft Graph REST API v1.0 and the Microsoft Graph REST API beta, respectively. Cmdlets are available for the installed modules.

Patch My PC

The Importance of Backing Up Microsoft Intune Configuration

Have you ever considered the importance of backing up your Microsoft Intune configurations? You dedicate hours to fine-tuning your Intune settings to deliver a better service to your customers. Losing any of these carefully configured settings from your environment unexpectedly can be frustrating and disruptive.

How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph - Fig .1
How to Backup anHow to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph. – Fig.1

Having a proper backup of all your Microsoft Intune configurations can be a lifesaver. A daily backup of your Intune configurations will streamline your processes and enhance your environment. Backing up and restoring your Intune configurations is simple with PowerShell and Microsoft Graph.

This article will cover the easiest method to install the MS Graph PowerShell module, back up Intune configurations, and restore Intune configurations. Make sure you have enough access to back up Intune configurations, and restore Intune configurations. Let’s start.

Install the MSGraphFunctions and IntuneBackupAndRestore Modules

You would need to install the necessary PowerShell modules before you automate the tasks. Let’s install the MSGraphFunctions and IntuneBackupAndRestore Modules.

  • Launch PowerShell as an Administrator.
  • Run the below command
Install-Module -Name MSGraphFunctions

When prompted, confirm with “Yes to All” to proceed. You can use -Force parameter ignore the prompt message. It may take some time to download and install the MSGraphFunctions Module.

How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph - Fig.2
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph. – Fig.2

You need to Install the IntuneBackupAndRestore module as well to proceed further. Run the following command to Install the Module. When prompted, confirm with “Yes to All” to proceed.

Install-Module -Name IntuneBackupAndRestore
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph - Fig.3
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph – Fig.3

Once the above modules are installed, you can Import both modules with below commands. Remember, you launch PowerShell as an Administrator. The modules will get imported quickly. You’re good to backing Up the Microsoft Intune Configurations.

Import-Module -Name MSGraphFunctions

Import-Module -Name IntuneBackupAndRestore

Authenticate with the Microsoft Graph

You must establish connection with the Microsoft Graph by running below command. Make sure you have enough access to authenticate. Open the PowerShell session as an Administrator and run the Connect-MgGraph command. New Microsoft Login page will popup, you must enter your credential to login.

Connect-MgGraph -ContextScope Process
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph - Fig.4
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph – Fig.4
NOTE! The -ContextScope Process parameter in the Connect-MgGraph cmdlet ensures that the authentication context is scoped to the current PowerShell process. This means that the authentication session remains active only within the running PowerShell instance and does not persist beyond it

Back Up the Microsoft Intune Configuration

Let’s start backing up your Microsoft Intune configurations. Running the command below will initiate the backup process. Specify the correct path where you want the backup files to be saved. I recommend storing them in a shared location. In this example, I am backing up the Intune configurations to E:\Backup_Intune.

Start-IntuneBackup -Path E:\Backup_Intune
ActionTypeNamePath
BackupIntune Backup and Restore ActionIntuneBackupAndRestore – Start Intune Backup Config and AssignmentsE:\Backup_Intune
How to Backup and Restore Microsoft Intune Configurations PowerShell and Microsoft Graph. – Table.1
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph - Fig.6
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph – Fig.6

The backup process may take a few minutes to complete. Verify the backed-up Microsoft Intune configurations in the path you specified in the command. My backed-up files are in E:\Backup_Intune folder.

How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph - Fig.7
How to How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph – Fig.7

Restore Microsoft Intune Configuration

We have successfully created a backup of all Microsoft Intune configurations. Now, let’s learn how to restore them in case any of these configured settings are unexpectedly lost from your environment. This step restores the configuration settings but does not include policy or app assignments.

For testing purposes, I have deleted all my configuration policies. Currently, there are no configuration policies in my lab. Let’s restore them.

How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph - Fig.8
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph – Fig.8

You can use the below command to Restore the configration from backup folder. You must open the PowerShell session as an Administrator and run the Connect-MgGraph command to sign in again.

Start-IntuneRestoreConfig E:\Backup_Intune
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph - Fig.9
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph- Fig.9

The configuration policies have been restored. Let’s verify this by navigating to Devices > Windows > Configuration in the Microsoft Intune Admin Portal.

How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph - Fig.10
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph – Fig.10

This step restored the configuration settings but does not include policy or app assignments. You could restore the Assignments run the following command.

Start-IntuneRestoreAssignments E:\Backup_Intune
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph - Fig.11
How to Backup and Restore Microsoft Intune Configurations using PowerShell and Microsoft Graph – Fig.11

I trust that this article will significantly benefit you and your organization. I appreciate your patience in reading this post. I look forward to seeing you in the next post. Keep supporting the HTMD Community.

Need Further Assistance or Have Technical Questions?

Join the LinkedIn Page and Telegram group to get the latest step-by-step guides and news updates. Join our Meetup Page to participate in User group meetings. Also, Join the WhatsApp Community to get the latest news on Microsoft Technologies. We are there on Reddit as well.

Author

About the Author: Sujin Nelladath, Microsoft Graph MVP with over 11 years of experience in SCCM device management and Automation solutions, writes and shares his experiences with Microsoft device management technologies, Azure, DevOps and PowerShell automation.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.