diff --git a/src/playbook/Configuration/atlas/start.yml b/src/playbook/Configuration/atlas/start.yml index 3c6ae4ae51..a493d5b030 100644 --- a/src/playbook/Configuration/atlas/start.yml +++ b/src/playbook/Configuration/atlas/start.yml @@ -6,19 +6,27 @@ actions: - !powerShell: wait: true command: >- - $modulesPath = """$([Environment]::GetFolderPath('Windows'))\AtlasModules"""; + function Add-ToPath ([array]$Paths) { + $machine = [System.EnvironmentVariableTarget]::Machine; + $seperator = [IO.Path]::PathSeparator; + + $Paths | ForEach-Object { + if (!(Test-Path $_ -PathType Container)) { + Write-Error """Path '$_' doesn't exist as a container.""" + } + }; - function AddToVar($env, $value) { - $a = [IO.Path]::PathSeparator; - $b = [System.EnvironmentVariableTarget]::Machine; - $c = [Environment]::GetEnvironmentVariables($b); + $newPath = @(); + $newPath += [Environment]::GetEnvironmentVariable('PATH', $machine) -split $seperator; + if ($newPath.Count -eq 0) { Write-Warning 'The PATH variable is currently empty.' }; + $newPath += $Paths; + $newPath = $newPath | Where-Object { $_ } | Select-Object -Unique; - [Environment]::SetEnvironmentVariable($env, - ("""$($c.'Path');$value""" -replace ';',"""$a"""), - $b); + [Environment]::SetEnvironmentVariable('PATH', """$($newPath -join $seperator)""", $machine); }; - AddToVar 'Path' """$modulesPath;$modulesPath\Apps;$modulesPath\Other;$modulesPath\Tools;$modulesPath\Scripts"""; + $modulesPath = """$([Environment]::GetFolderPath('Windows'))\AtlasModules"""; + Add-ToPath """$modulesPath""", """$modulesPath\Apps""", """$modulesPath\Other""", """$modulesPath\Tools""", """$modulesPath\Scripts"""; ################ NO LOCAL BUILD ################