Skip to content

Instantly share code, notes, and snippets.

@denelon
Created April 18, 2023 17:51
Show Gist options
  • Save denelon/23d9f4c565687519ffcc7d5355f64bdb to your computer and use it in GitHub Desktop.
Save denelon/23d9f4c565687519ffcc7d5355f64bdb to your computer and use it in GitHub Desktop.
Sample configuration to set a machine scoped environment variable
# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.1
# Requires administrator
# Checks for absences of environment variable and sets it if it's not present.
properties:
configurationVersion: '0.1.0'
assertions:
- resource: Environment
directives:
module: PSDscResources
settings:
Name: 'DSC_EXAMPLE'
Ensure: 'Absent'
Value: 'Desired State Configuration'
Target: 'Machine'
resources:
- resource: Environment
directives:
module: PSDscResources
settings:
Name: 'DSC_EXAMPLE'
Ensure: 'Present'
Value: 'Desired State Configuration'
Target: 'Machine'
@dmealo
Copy link

dmealo commented Aug 28, 2023

Add the code to your hypothetical PS script that does the same thing to enable the other features this does (DSC, for example) then the argument for this is easier to understand. The gist does mention this is a contrived example though, too. More powerful assertions are available and possible which augment the benefit of this approach. See the Winget Configuration docs for more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment