Desired State Configuration setup
This page describes the setup of Microsoft 365 Dynamic State Configuration (DSC)
Estimated reading time: 3 minutes
Overview
Microsoft 365 Desired State Configuration (M365DSC) is a configuration-as-code tool developed by Microsoft to automate the configuration of Microsoft 365 services. It is the primary tool used to automate the deployment of the configuration guidance in the Blueprint.
After following the steps below, please refer to the automated deployment or configuration assessment pages for further instructions.
Prerequisites
To deploy or assess an M365DSC configuration, the following prerequisites are required:
- Knowledge of the Microsoft M365DSC prerequisites.
- An admin account on a Windows host with connectivity to Entra ID and Microsoft 365, and with:
- The DSC file for the targeted M365 service (discussed below).
- A DSC configuration data file from a configuration index page.
1. Create certificates and keys for authentication
On the Windows host used for deployment, execute the following commands in an elevated PowerShell prompt to create a PFX file that will be used for authentication, substituting a password of your choice and the location of your working folder:
$certname = 'M365DSC'
$cert = New-SelfSignedCertificate -Subject "CN=$certname" -CertStoreLocation 'Cert:\CurrentUser\My' -KeyExportPolicy Exportable -KeySpec Signature -KeyLength 2048 -KeyAlgorithm RSA -HashAlgorithm SHA256
$password = ConvertTo-SecureString -String '<password>' -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath 'C:\<location>\M365DSC.pfx' -Password $password
2. Import the PFX file into the Local Computer certificate store
- Double-click the
M365DSC.pfx
file to begin the import wizard. - Select Local Machine and accepting the defaults, follow the prompts to complete the wizard.
3. Export the leaf certificate from the Local Computer certificate store
- Open the Local Computer certificate store (Start > Manage Computer certificates) and navigate to Personal\Certificates.
- Right-click the M365DSC certificate, then select All Tasks > Export to begin the export wizard.
- Accepting the defaults, follow the prompts to complete the wizard, specifying
C:\<location>\M365DSC.cer
as the file name, substituting location with the name of your working folder.
4. Register an app and service principal in Entra
Authenticate to your Entra tenant with an account with permissions to register an app and update the app’s permissions:
$creds = Get-Credential
Create the app, specifying the exported certificate to be used for authentication, substituting location with the name of your working folder:
Update-M365DSCAzureAdApplication -ApplicationName 'M365DSC' -Type Certificate -CertificatePath 'C:\<location>\M365DSC.cer' -Permissions @( @{Api='Graph';PermissionName='Organization.Read.All'} ) -Credential $creds
Grant admin consent
You will be required to manually grant admin consent to the app’s permissions, this can be done in the Entra portal under the API permissions section of the M365DSC app. This process will also create a service principal named M365DSC.
There may also be a delay in updating the permissions via Powershell and having them appear in the portal.
Remove permissions
Permissions should always be removed after DSC operations.
5. Download and edit the configuration data file
- Download the configuration data file, renaming the linked .txt file to .psd1.
- Edit the configuration data file to suit, substituting your Entra tenant and M365DSC app configurations:
# Your Entra tenant ID
TenantId = '<GUID>'
# Your Entra primary domain name
OrganizationName = '<organisation>.onmicrosoft.com'
# The Application ID of your app
ApplicationId = '<GUID>'
# The thumbprint of the certificate to authenticate your app
# This can be found in the certificates and secrets section of your app or in the the details tab of the exported CER file.
CertificateThumbprint = '<thumbprint hash>'
Refer to the automated deployment or configuration assessment pages for further instructions.
Related information
Configuration
- Microsoft Defender
- Microsoft Entra ID
- Microsoft Exchange Online
- Microsoft Intune
- Microsoft Purview
- Microsoft SharePoint Online
- Microsoft Teams