Created
July 18, 2016 15:01
-
-
Save gaelcolas/42f283727435c641a83419c764203ee3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Ensure { | |
Absent | |
Present | |
} | |
[DscResource()] | |
Class Env_Refresh { | |
[DSCProperty(Mandatory)] | |
[Ensure] $Ensure | |
[DSCProperty(key)] | |
[string]$RunName | |
[DSCProperty(Mandatory)] | |
[string[]]$VariableNameList | |
[void] Set() | |
{ | |
Write-Verbose "EnvironmentVariableRefresh for $($this.Ensure)::$($this.RunName)" | |
if ($this.VariableNameList -eq '*') | |
{ | |
$this.VariableNameList = [Environment]::GetEnvironmentVariables().Keys | |
} | |
if ($this.Ensure -eq [Ensure]::Present) | |
{ | |
foreach ($variableName in $this.VariableNameList) | |
{ | |
Write-Verbose "Processing $($this.RunName)::$variableName" | |
$VariableValue = [environment]::GetEnvironmentVariable($variableName,[EnvironmentVariableTarget]::Machine) | |
[Environment]::SetEnvironmentVariable($variableName,$VariableValue, [EnvironmentVariableTarget]::Process) | |
} | |
} | |
} | |
[Env_Refresh] Get() | |
{ | |
Write-Verbose "Returning This instance for GET: Ensure:$($this.Ensure.ToString()) $($this.RunName)" | |
return $this | |
} | |
[bool] Test() | |
{ | |
return $false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment