Skip to content

Instantly share code, notes, and snippets.

@gaelcolas
Created July 18, 2016 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaelcolas/42f283727435c641a83419c764203ee3 to your computer and use it in GitHub Desktop.
Save gaelcolas/42f283727435c641a83419c764203ee3 to your computer and use it in GitHub Desktop.
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