Environment Resource
Synopsis
Manages Windows environment variables at the User or Machine scope.
Type
Capabilities
- Get
- Set
- Delete
- Export
Properties
name
The name of the environment variable.
value
The value of the environment variable.
scope
The scope. Accepts User or Machine.
_exist
Whether the variable should exist.
Note
Setting scope to Machine requires administrator privileges.
Examples
Example 1 — Get an environment variable
Example 2 — Set an environment variable
Example 3 — Delete an environment variable
Example 4 — Export all environment variables
Example 5 — Configuration document
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Set application home
type: OpenDsc.Windows/Environment
properties:
name: APP_HOME
value: C:\MyApp
scope: Machine
- name: Remove legacy variable
type: OpenDsc.Windows/Environment
properties:
name: LEGACY_VAR
scope: User
_exist: false
Exit codes
| Code | Description |
|---|---|
| 0 | Success |
| 1 | Error |
| 2 | Invalid JSON |
| 3 | Access denied |
| 4 | Invalid argument |