Dynamic Resource Generator¶
The Microsoft365DSC Dynamic Resource Generator (DRG) is a PowerShell module and a set of templates that automatically generate class-based Microsoft365DSC resources, their MOF schemas, examples, and unit tests. Microsoft Graph based resources are generated from the Graph OpenAPI (CSDL) metadata; resources for the other workloads (Exchange Online, Teams, Security & Compliance, PnP, Power Platforms) are generated by introspecting the workload's cmdlets. The DRG is included as part of the main Microsoft365DSC codebase.
Why the DRG?¶
Microsoft 365 is evolving at a rapid pace, with new features being released on a regular basis and other legacy configuration items being deprecated. So far, the Microsoft365DSC team has been manually creating the DSC resources that make up the solution, which has been very time-consuming and requires constant updating as these resources change and evolve. The Dynamic Resource Generator reduces that manual effort: point it at a cmdlet and it produces a resource that follows the current class-based resource pattern, with very little manual work left before the resource is ready.
What gets generated¶
For a resource named <Name>, one command produces:
- Resource module -
MSFT_<Name>\MSFT_<Name>.psm1: a[DscResource()]class deriving fromM365DSCResourceBase, withGet(),Set(),Test()andExport()methods, embedded CIM classes for complex types and per-resource helper functions. - MOF schema -
MSFT_<Name>\MSFT_<Name>.schema.mof: generated from the same property model as the class, so the two cannot drift apart. - settings.json - including the
permissions(scraped from Graph),requiredModulesandcommandssections. Only therolessection needs to be filled in manually. - readme.md
- Unit test -
Microsoft365DSC.<Name>.Tests.ps1in the current class-based test pattern: it asserts every scalar property value returned byGet(), and its drift context uses genuinely different values. - Examples -
1-Create.ps1,2-Update.ps1and3-Remove.ps1, each genuinely distinct (create uses the baseline values, update uses drifted values, remove keeps only the keys). - Unit test stubs - the cmdlet stubs are appended to
Tests\Unit\Stubs\Microsoft365.psm1when missing.
Intune resources with assignments automatically get the Assignments property together with the shared ConvertFrom/ConvertTo-IntunePolicyAssignment plumbing.
Generation is non-interactive by default. When a Graph entity is polymorphic (e.g. device compliance policies), the concrete OData subtype is picked automatically by name similarity with the resource name and cmdlet noun. An explicit -AdditionalPropertiesType always wins, and only an ambiguous match in an interactive session falls back to a prompt.
All artifacts are written to a staging folder first and moved into place only when the whole generation succeeds, so a failure never leaves a half-generated resource behind.
Getting Started¶
The DRG files are located at the root of the project under the ResourceGenerator folder. Import the module through its manifest and run New-M365DSCResource:
| Parameter Name | Required | Accepted Values | Description |
|---|---|---|---|
| ResourceName | True | String | The name of the resource to be generated. E.g., AADDomain, IntuneResourceX, etc. |
| Workload | True | String. Any of: "ExchangeOnline", "Intune", "MicrosoftGraph", "MicrosoftTeams", "PnP", "PowerPlatforms", "SecurityComplianceCenter" | The name of the Microsoft 365 workload associated with the resource to be generated |
| CmdLetNoun | True | String | The noun part of the cmdlet associated with the resource. E.g., for the AADDomain resource, the associated cmdlet is Get-MgBetaDomain, so the value is 'MgBetaDomain'. |
| CmdLetVerb | False | String | Non-Graph workloads only: the verb of the cmdlet whose parameters describe the resource. Defaults to 'New'. |
| IsSingleInstance | False | Switch | Generates a singleton resource with an IsSingleInstance key and no Ensure property. |
| Path | False | String | Folder receiving the resource folder. Defaults to the repository's Modules\Microsoft365DSC\DscResources. |
| UnitTestPath | False | String | Folder receiving the unit test. Defaults to Tests\Unit\Microsoft365DSC. |
| ExampleFilePath | False | String | Folder receiving the examples. Defaults to Examples\Resources. |
| APIVersion | False | String. Any of: "v1.0", "beta" | The Microsoft Graph API version to use. Falls back to beta automatically when the cmdlet only exists there. |
| ParametersToSkip | False | String[] | Property names to leave out of the generated resource. |
| AdditionalPropertiesType | False | String | The concrete OData subtype for polymorphic Graph entities, bypassing the automatic name-based selection. |
| FixActualType | False | String | The Graph entity type, when it cannot be derived from the cmdlet's output type. |
| IncludeNavigationProperties | False | Boolean | Includes Graph navigation properties (relationships). Use with caution and only when a relationship carries writable properties. |
| SettingsCatalogTemplateId | False | String | Generates an Intune settings catalog resource from a configuration policy template, e.g. '4cfd164c-5e8a-4ea9-b15d-9aa71e4ffff4_1'. The setting templates, platforms, technologies and template reference are fetched from Graph automatically - an authenticated Microsoft Graph connection (Connect-MgGraph) is required. |
| SettingsCatalogSettingTemplates | False | Array | Already-fetched setting templates (with expanded settingDefinitions); optional alternative to letting the generator fetch them. |
| SkipPlatformsAndTechnologies | False | Switch | For a settings catalog resource, removes the Platforms and Technologies settings from the generated parameters. |
| NonInteractive | False | Switch | Suppresses every prompt; ambiguity becomes an error with retry guidance. |
| Force | False | Switch | Overwrites existing generated files. |
The Graph CSDL metadata is downloaded once and cached under %LOCALAPPDATA%\M365DSC\ResourceGenerator, so repeat generations work offline.
As an example, to generate the AADDomain resource, run:
cd C:\Github\Microsoft365DSC\ResourceGenerator
Import-Module .\M365DSCResourceGenerator.psd1
New-M365DSCResource `
-ResourceName AADDomain `
-Workload MicrosoftGraph `
-CmdLetNoun 'MgBetaDomain' `
-APIVersion beta
After generation:
- Review the generated
Set()logic - create/update parameter shaping is resource-specific and may need adjustments for non-standard APIs. - Fill the
rolessection ofsettings.json. - Run
Utilities\Build-Microsoft365DSC.ps1, then run the generated unit test with Pester.
To generate an Intune settings catalog resource, connect to Graph first and pass the template id:
Connect-MgGraph -ClientId $appId -TenantId $tenantId -CertificateThumbprint $thumbprint
New-M365DSCResource `
-ResourceName IntuneDefenderAntivirusPolicyLinux `
-Workload Intune `
-CmdLetNoun 'MgBetaDeviceManagementConfigurationPolicy' `
-SettingsCatalogTemplateId '4cfd164c-5e8a-4ea9-b15d-9aa71e4ffff4_1'
Templates that mix device_ and user_ scoped settings (e.g. Account Protection, Security Baselines) automatically get the split DeviceSettings/UserSettings surface, matching resources like MSFT_IntuneAccountProtectionPolicyWindows10. Resource, CIM class and test/example properties are emitted in alphabetical order.
Known limitations¶
- Settings Catalog support is best-effort: duplicate setting names across templates are skipped with a warning, and generated Get()/Set() conversion of deeply nested group settings should be reviewed.
- Exchange Online cmdlets only exist after
Connect-ExchangeOnline, so generating EXO resources requires an active connection.
The generator's own unit tests live under ResourceGenerator\Tests and run offline: Invoke-Pester -Path .\ResourceGenerator\Tests.
We are currently looking for users to help us test and improve the DRG. If you are interested in helping out, please try it out with the instructions above and report any issues or questions in the Issues section of the GitHub repository mentioning that the item is related to the DRG testing.