Skip to main content
The WinGet DSC module provides Desired State Configuration (DSC) resources for managing Windows Package Manager in a declarative way.

What is DSC?

Desired State Configuration (DSC) is a declarative platform for configuring Windows systems. Instead of writing imperative scripts, you declare the desired state of your system, and DSC ensures that state is achieved and maintained.

WinGet DSC Resources

The Microsoft.WinGet.DSC module provides five DSC resources:

WinGetPackage

Manage package installation state

WinGetSource

Manage package sources

WinGetUserSettings

Configure user settings

WinGetAdminSettings

Configure admin settings

WinGetPackageManager

Ensure WinGet is installed

Installation

Install the DSC module from PowerShell Gallery:
Install-Module -Name Microsoft.WinGet.DSC -Scope CurrentUser

Using DSC Resources

DSC resources can be used in two ways: Define resources in YAML configuration files:
properties:
  resources:
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      directives:
        description: Install PowerToys
      settings:
        id: Microsoft.PowerToys
        source: winget
Apply with configuration cmdlets:
$config = Get-WinGetConfiguration -File "setup.yaml"
Invoke-WinGetConfiguration -Set $config -AcceptConfigurationAgreements

2. PowerShell DSC Configuration

Use resources in PowerShell DSC configurations:
Configuration DevSetup {
    Import-DscResource -ModuleName Microsoft.WinGet.DSC
    
    WinGetPackage PowerToys {
        Id = "Microsoft.PowerToys"
        Source = "winget"
        Ensure = "Present"
    }
}

Resource: WinGetPackage

Manages the installation state of packages.

Properties

Id
string
required
The package identifier (key property).
Source
string
The source name (key property).
Version
string
The specific version to install.
Ensure
enum
default:"Present"
Whether the package should be Present or Absent.
MatchOption
enum
default:"EqualsCaseInsensitive"
How to match the package ID: Equals, EqualsCaseInsensitive, StartsWithCaseInsensitive, ContainsCaseInsensitive.
UseLatest
bool
default:"false"
Always keep the package updated to the latest version.
InstallMode
enum
default:"Silent"
Installation mode: Default, Silent, Interactive.

Example

- resource: Microsoft.WinGet.DSC/WinGetPackage
  settings:
    id: Microsoft.PowerToys
    source: winget
    ensure: Present
    useLatest: true

Resource: WinGetSource

Manages package sources.

Properties

Name
string
required
The source name (key property).
Argument
string
required
The source URL or argument.
Type
string
The source type (e.g., “Microsoft.PreIndexed.Package”).
TrustLevel
enum
default:"Undefined"
Trust level: Undefined, None, Trusted.
Explicit
bool
Whether the source requires explicit selection.
Priority
int
The source priority.
Ensure
enum
default:"Present"
Whether the source should be Present or Absent.

Example

- resource: Microsoft.WinGet.DSC/WinGetSource
  settings:
    name: custom-repo
    argument: https://example.com/packages
    type: Microsoft.PreIndexed.Package
    trustLevel: Trusted
    ensure: Present

Resource: WinGetUserSettings

Manages WinGet user settings.

Properties

SID
string
required
User identifier (key property, do not set manually).
Settings
hashtable
required
Hashtable of settings to configure.
Action
enum
default:"Full"
Full (replace all settings) or Partial (merge with existing).

Example

- resource: Microsoft.WinGet.DSC/WinGetUserSettings
  settings:
    sid: ""
    settings:
      visual:
        progressBar: rainbow
      telemetry:
        disable: true
    action: Partial

Resource: WinGetAdminSettings

Manages WinGet administrator settings (requires admin privileges).

Properties

SID
string
required
System identifier (key property, do not set manually).
Settings
hashtable
required
Hashtable of admin settings to configure.

Example

- resource: Microsoft.WinGet.DSC/WinGetAdminSettings
  settings:
    sid: ""
    settings:
      LocalManifestFiles: true
      BypassCertificatePinningForMicrosoftStore: false

Resource: WinGetPackageManager

Ensures WinGet is installed and optionally at a specific version.

Properties

SID
string
required
System identifier (key property, do not set manually).
Version
string
Specific version to install.
UseLatest
bool
default:"false"
Install the latest stable version.
UseLatestPreRelease
bool
default:"false"
Install the latest pre-release version.

Example

- resource: Microsoft.WinGet.DSC/WinGetPackageManager
  settings:
    sid: ""
    useLatest: true

Complete Configuration Example

properties:
  configurationVersion: 0.2.0
  resources:
    # Ensure WinGet is installed
    - resource: Microsoft.WinGet.DSC/WinGetPackageManager
      settings:
        sid: ""
        useLatest: true
    
    # Configure user settings
    - resource: Microsoft.WinGet.DSC/WinGetUserSettings
      settings:
        sid: ""
        settings:
          visual:
            progressBar: rainbow
        action: Partial
    
    # Add custom source
    - resource: Microsoft.WinGet.DSC/WinGetSource
      settings:
        name: company-repo
        argument: https://packages.company.com
        ensure: Present
    
    # Install packages
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      settings:
        id: Microsoft.PowerToys
        source: winget
        useLatest: true
    
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      settings:
        id: Microsoft.VisualStudioCode
        source: winget
        version: 1.85.0

Testing DSC Resources

Test if the system is in the desired state:
# Test a single resource
$resource = [WinGetPackage]@{
    Id = "Microsoft.PowerToys"
    Source = "winget"
    Ensure = "Present"
}
$resource.Test()

Best Practices

  1. Use Configuration Files: Prefer YAML configuration files over PowerShell DSC scripts
  2. Version Control: Store configuration files in version control
  3. Test First: Test configurations in development before production
  4. Idempotent: DSC resources are idempotent - safe to run multiple times
  5. Admin Rights: Some resources (WinGetAdminSettings, WinGetSource) require admin privileges
  6. UseLatest: Use useLatest: true for packages that should stay current

Next Steps

DSC Resources Reference

Detailed reference for all DSC resources

Configuration Overview

Learn about configuration files

Getting Started

Get started with WinGet PowerShell

Build docs developers (and LLMs) love