title | ms.date | keywords | description | ms.topic | author | manager | ms.prod |
---|---|---|---|---|---|---|---|
DSC Environment Resource |
2016-05-16 |
powershell,DSC |
article |
eslesar |
dongill |
powershell |
Applies To: Windows PowerShell 4.0, Windows PowerShell 5.0
The Environment resource in Windows PowerShell Desired State Configuration (DSC) provides a mechanism to manage system environment variables.
Environment [string] #ResourceName
{
Name = [string]
[ Ensure = [string] { Absent | Present } ]
[ Path = [bool] ]
[ DependsOn = [string[]] ]
[ Value = [string] ]
}
Property | Description |
---|---|
Name | Indicates the name of the environment variable for which you want to ensure a specific state. |
Ensure | Indicates if a variable exists. Set this property to Present to create the environment variable if it does not exist or to ensure that its value matches what is provided through the Value property if the variable already exists. Set it to Absent to delete the variable if it exists. |
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. |
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" . |
Value | The value to assign to the environment variable. |
The following example ensures that TestEnvironmentVariable is present and it has the value TestValue. If it is not present, it creates it.
Environment EnvironmentExample
{
Ensure = "Present" # You can also set Ensure to "Absent"
Name = "TestEnvironmentVariable"
Value = "TestValue"
}