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'
@g0t4
Copy link

g0t4 commented Jun 4, 2023

No offense intended... are these files intended to be created/modified manually? If so, wow this is incredibly verbose to set a single env var. This is a case study in why declarative has major flaws too :)

@seankearon
Copy link

I agree with @g0t4 - this seems to be a substantial amount of effort to configure these when compared with just running a simple PowerShell script.

@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