Export resource instances
Some OpenDSC resources support the Export operation, which enumerates all current instances of that resource on the system. This is useful for discovering existing state and generating baseline configurations.
When to use this guide
Use export when you need to:
- Discover all environment variables, users, groups, or other resources on a system.
- Generate a baseline configuration document from existing state.
- Audit what's currently configured on a machine.
Check export capability
Not all resources support export. Check the capabilities column in the resource list:
dsc resource list OpenDsc* | ConvertFrom-Json |
Where-Object { $_.capabilities -match 'e' } |
Select-Object type, capabilities
The e flag in the capabilities column indicates export support.
Export all instances
Use dsc resource export to retrieve all instances:
The output contains every instance of the resource as a configuration document:
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: 'Environment: PATH (Machine)'
type: OpenDsc.Windows/Environment
properties:
name: PATH
value: C:\Windows\system32;C:\Windows;...
scope: Machine
- name: 'Environment: TEMP (User)'
type: OpenDsc.Windows/Environment
properties:
name: TEMP
value: C:\Users\admin\AppData\Local\Temp
scope: User
Save export output to a file
Redirect the output to a file to create a baseline configuration:
Export from multiple resources
Use dsc config export with a configuration document that lists the resources
you want to export: