Skip to main content

Introduction & procedure of Microsoft 365 DSC

With this tool you can export your Microsoft 365 tenant as code. This code can then be backed up, customized or restored to another environment. This makes it possible to keep several environments congruent and enables you to automate and execute integrety checks regularly thanks to the programmatic style of Microsoft 365 DSC.

Preparations

You have to install the module and update the dependencies first. Administrator rights on Windows are required for this installation step.

Install-Module Microsoft365DSC
Update-M365DSCDependencies

Download tenant configuration

For downloading an existing tenant configuration you have to add the credentials to a variable. This variable is required as the export can sometimes take over 1 hour. During this time, the access token will have expired and must be requested again. It is suggested to use an account or identity with Global Admin permissions and MFA disabled.

$Credential = Get-Credential

You can compile the final export statement yourself. It is best to click together the PowerShell command via this website and define the required export values: https://export.microsoft365dsc.com.

Export-M365DSCConfiguration -Components @(<yourconfigurations>) -Credential $Credential

Apply existing configuration

Importing is the same as exporting configurations. The access data for the tenant must be stored in a variable and configured without MFA.

$Credential = Get-Credential

First, the configuration is assembled from the PowerShell script with the credential data to a .mob file.

.\M365TenantConfig.ps1 -Credential $Credential

The .mob file is then applied to the environment using the standard DSC module. 

Start-DscConfiguration -Path .\M365TenantConfig\ -Wait -Verbose -Force