|
1 | 1 | ---
|
2 |
| -ms.date: 06/12/2017 |
3 |
| -keywords: dsc,powershell,configuration,setup |
4 |
| -title: DSC for Linux nxEnvironment Resource |
| 2 | +ms.date: 09/20/2019 |
| 3 | +keywords: dsc,powershell,configuration,setup |
| 4 | +title: DSC for Linux nxEnvironment Resource |
5 | 5 | ---
|
6 |
| - |
7 | 6 | # DSC for Linux nxEnvironment Resource
|
8 | 7 |
|
9 |
| -The **nxEnvironment** resource in PowerShell Desired State Configuration (DSC) provides a mechanism to manage system environment variables on a Linux node. |
| 8 | +The **nxEnvironment** resource in PowerShell Desired State Configuration (DSC) provides a mechanism |
| 9 | +to manage system environment variables on a Linux node. |
10 | 10 |
|
11 | 11 | ## Syntax
|
12 | 12 |
|
13 |
| -``` |
| 13 | +```Syntax |
14 | 14 | nxEnvironment <string> #ResourceName
|
15 | 15 | {
|
16 | 16 | Name = <string>
|
17 | 17 | [ Value = <string>
|
18 |
| - [ Ensure = <string> { Absent | Present } ] |
19 | 18 | [ Path = <bool> }
|
20 | 19 | [ DependsOn = <string[]> ]
|
21 |
| -
|
| 20 | + [ Ensure = <string> { Absent | Present } ] |
22 | 21 | }
|
23 | 22 | ```
|
24 | 23 |
|
25 | 24 | ## Properties
|
26 | 25 |
|
27 |
| -| Property | Description | |
| 26 | +|Property |Description | |
28 | 27 | |---|---|
|
29 |
| -| Name| Indicates the name of the environment variable for which you want to ensure a specific state.| |
30 |
| -| Value| The value to assign to the environment variable.| |
31 |
| -| Ensure| Determines whether to check if the variable exists. Set this property to "Present" to ensure the variable exists. Set it to "Absent" to ensure the variable does not exist. The default value is "Present".| |
32 |
| -| Path| Defines the environment variable that is being configured. Set this property to **$true** if the variable is the **Path** variable; otherwise, set it to **$false**. The default is **$false**. If the variable being configured is the **Path** variable, the value provided through the **Value** property will be appended to the existing value.| |
33 |
| -| DependsOn | Indicates that the configuration of another resource must run before this resource is configured. For example, if the **ID** of the resource configuration script block that you want to run first is **ResourceName** and its type is **ResourceType**, the syntax for using this property is `DependsOn = "[ResourceType]ResourceName"`.| |
| 28 | +|Name |Indicates the name of the environment variable for which you want to ensure a specific state. | |
| 29 | +|Value |The value to assign to the environment variable. | |
| 30 | +|Path |Defines the environment variable that is being configured. Set this property to `$true` if the variable is the **Path** variable; otherwise, set it to `$false`. The default is `$false`. If the variable being configured is the **Path** variable, the value provided through the **Value** property will be appended to the existing value. | |
| 31 | + |
| 32 | +## Common properties |
| 33 | + |
| 34 | +|Property |Description | |
| 35 | +|---|---| |
| 36 | +|DependsOn |Indicates that the configuration of another resource must run before this resource is configured. For example, if the ID of the resource configuration script block that you want to run first is ResourceName and its type is ResourceType, the syntax for using this property is `DependsOn = "[ResourceType]ResourceName"`. | |
| 37 | +|Ensure |Determines whether to check if the variable exists. Set this property to **Present** to ensure the variable exists. Set it to **Absent** to ensure the variable does not exist. The default value is **Present**. | |
34 | 38 |
|
35 | 39 | ## Additional Information
|
36 | 40 |
|
37 |
| -* If **Path** is absent or set to **$false**, environment variables are managed in `/etc/environment`. Your programs or scripts may require configuration to source the `/etc/environment` file to access the managed environment variables. |
38 |
| -* If **Path** is set to **$true**, the environment variable is managed in the file `/etc/profile.d/DSCenvironment.sh`. This file will be created if it does not exist. If **Ensure** is set to "Absent" and **Path** is set to **$true**, an existing environment variable will only be removed from `/etc/profile.d/DSCenvironment.sh` and not from other files. |
| 41 | +- If **Path** is absent or set to `$false`, environment variables are managed in `/etc/environment`. |
| 42 | + Your programs or scripts may require configuration to source the `/etc/environment` file to access |
| 43 | + the managed environment variables. |
| 44 | +- If **Path** is set to `$true`, the environment variable is managed in the file |
| 45 | + `/etc/profile.d/DSCenvironment.sh`. This file will be created if it does not exist. If **Ensure** |
| 46 | + is set to **Absent** and **Path** is set to `$true`, an existing environment variable will only be |
| 47 | + removed from `/etc/profile.d/DSCenvironment.sh` and not from other files. |
39 | 48 |
|
40 | 49 | ## Example
|
41 | 50 |
|
42 |
| -The following example shows how to use the **nxEnvironment** resource to ensure that **TestEnvironmentVariable** is present and has the value "Test-Value". If **TestEnvironmentVariable** is not present, it will be created. |
| 51 | +The following example shows how to use the **nxEnvironment** resource to ensure that |
| 52 | +**TestEnvironmentVariable** is present and has the value "Test-Value". If |
| 53 | +**TestEnvironmentVariable** is not present, it will be created. |
43 | 54 |
|
44 |
| -``` |
| 55 | +```powershell |
45 | 56 | Import-DSCResource -Module nx
|
46 | 57 |
|
47 |
| -
|
48 | 58 | nxEnvironment EnvironmentExample
|
49 | 59 | {
|
50 |
| - Ensure = “Present” |
51 |
| - Name = “TestEnvironmentVariable” |
52 |
| - Value = “TestValue” |
| 60 | + Ensure = "Present" |
| 61 | + Name = "TestEnvironmentVariable" |
| 62 | + Value = "TestValue" |
53 | 63 | }
|
54 | 64 | ```
|
0 commit comments