Skip to content

Instantly share code, notes, and snippets.

@denelon
Last active June 4, 2023 13:20
Show Gist options
  • Save denelon/b1ebafcb39331cec7dcdcea1a35ef162 to your computer and use it in GitHub Desktop.
Save denelon/b1ebafcb39331cec7dcdcea1a35ef162 to your computer and use it in GitHub Desktop.
Checks for presence of environment variable and removes it
# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.1
# Requires administrator
# Checks for presence of environment variable and removes it if it's present.
properties:
configurationVersion: '0.1.0'
assertions:
- resource: Environment
directives:
module: PSDscResources
settings:
Name: 'DSC_EXAMPLE'
Ensure: 'Present'
Value: 'Desired State Configuration'
Target: 'Machine'
resources:
- resource: Environment
directives:
module: PSDscResources
settings:
Name: 'DSC_EXAMPLE'
Ensure: 'Absent'
Value: 'Desired State Configuration'
Target: 'Machine'
@g0t4
Copy link

g0t4 commented Jun 4, 2023

Isn't it redundant to check (assert) if the env var exists before removing it? That's imperative, not declarative. In a declarative model describing a resource as absent should be all that's required.

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