DSC Integration
WinGet integrates with PowerShell Desired State Configuration (DSC) to enable configuration as code scenarios. This allows you to define your development environment, applications, and settings in declarative configuration files.Overview
WinGet configuration enables:- Declarative setup - Define desired system state in YAML files
- Reproducible environments - Share and recreate development environments
- Automated provisioning - Apply configurations programmatically
- State management - Test, get, and set system configuration
WinGet configuration is built on the Microsoft.Management.Configuration API and supports both DSC v2 (PowerShell-based) and DSC v3 (PowerShell-free) resources.
Configuration Files
Configuration files are YAML documents that describe the desired state of your system.Basic Structure (DSC v2)
DSC v3 Structure
Configuration Schema
Properties Section
Configuration syntax version (e.g., “0.2”).
List of resources to configure.
Preconditions required to run the configuration.
Resources that retrieve information via ‘get’ operation.
Resource Definition
Each resource in the configuration defines a unit of desired state:Name of the resource (e.g., “Microsoft.WinGet.DSC/WinGetPackage”).
Unique identifier for this resource instance.
List of resource IDs this resource depends on.
Metadata about the module and resource.
Configuration parameters for the resource.
WinGet DSC Resources
WinGet provides several DSC resources for package and source management.WinGetPackage
Manage package installation state.Package identifier from the source.
Source name providing the package (e.g., “winget”, “msstore”).
Specific package version to install.
Whether package should be installed (
Present) or not (Absent).Update to latest version (overrides
Version).How to match the package Id:
Equals, EqualsCaseInsensitive, StartsWithCaseInsensitive, ContainsCaseInsensitive.Installation interactivity:
Default, Silent, Interactive.WinGetSource
Configure WinGet package sources.Source name.
Source URI or identifier.
Source type:
Microsoft.PreIndexed.Package, Microsoft.Rest.Trust level:
Undefined, None, Trusted.Whether source is excluded from default searches (
true) or included (false).Whether source should exist (
Present) or not (Absent).WinGetPackageManager
Ensure WinGet itself is at a specific version.User SID (currently only empty string "" is supported for current user).
Specific WinGet version to install.
Install latest stable release.
Install latest preview release.
WinGetUserSettings / WinGetAdminSettings
Manage WinGet settings files.PowerShell Configuration Module
Use WinGet configuration from PowerShell.Installation
The configuration module is included with WinGet (version 1.4+):Available Cmdlets
Get-WinGetConfiguration
Get-WinGetConfiguration
Load a configuration file.Parameters:
-File <string>- Path to configuration YAML file
Get-WinGetConfigurationDetails
Get-WinGetConfigurationDetails
Get detailed information about configuration resources.Parameters:
-Set <PSConfigurationSet>- Configuration set to inspect
Invoke-WinGetConfiguration
Invoke-WinGetConfiguration
Apply a configuration synchronously.Parameters:
-Set <PSConfigurationSet>- Configuration to apply-AcceptConfigurationAgreements- Accept all agreements automatically
Start-WinGetConfiguration
Start-WinGetConfiguration
Apply a configuration asynchronously.Parameters:
-Set <PSConfigurationSet>- Configuration to apply-AcceptConfigurationAgreements- Accept all agreements
Complete-WinGetConfiguration
Complete-WinGetConfiguration
Wait for an asynchronous configuration to complete.Parameters:
-ConfigurationJob <PSConfigurationJob>- Job to wait for
Configuration Examples
Development Environment Setup
Corporate Environment Configuration
Multi-Language Development Setup
Configuration Directives
Directives provide metadata and control how resources are processed.PowerShell module name containing the resource.
Human-readable description of what the resource does.
Allow prerelease versions of PowerShell modules.
Security context for execution:
current, restricted, elevated.Dependency Management
UsedependsOn to control resource application order:
Configuration Variables
Use variables to make configurations dynamic:${WinGetConfigRoot}- Root directory of the configuration file- Environment variables (e.g.,
${USERPROFILE},${TEMP})
Testing Configurations
Test configuration without applying:Configuration History
WinGet tracks applied configurations:Troubleshooting
Configuration fails to load
Configuration fails to load
- Validate YAML syntax
- Check
configurationVersionis specified - Verify resource names are correct
- Ensure schema reference is valid (for DSC v3)
Resource not found
Resource not found
- Verify PowerShell module is installed
- Check module name in
directives.module - Set
allowPrerelease: trueif using prerelease modules - Ensure WinGet version supports the resource
Dependency errors
Dependency errors
- Check for circular dependencies
- Verify all referenced IDs exist
- Ensure dependency order is logical
- Test dependencies individually
Permission denied
Permission denied
- Add
securityContext: elevatedto directives - Run PowerShell as administrator
- Check if package requires elevation
- Verify user has necessary permissions
Best Practices
- Use version control - Store configuration files in Git
- Add descriptions - Document each resource’s purpose
- Handle dependencies - Explicitly define resource dependencies
- Test incrementally - Test resources individually before combining
- Use assertions - Validate preconditions before applying
- Security context - Only elevate when necessary
- Modularize - Split large configurations into smaller files
- Version packages - Pin critical packages to specific versions
See Also
- Settings Configuration - Configure WinGet behavior
- Experimental Features - Enable experimental capabilities
- WinGet Configure Command - Apply configuration files
- Microsoft.Management.Configuration API - API reference