Last active
March 6, 2017 03:39
-
-
Save maoizm/c494afb991000413f583486473cfab41 to your computer and use it in GitHub Desktop.
sets environment variables for Machine and User
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
# | |
# Initializes Environment variables both globally and for current user session | |
# | |
# for login sessions run via | |
# | |
# powershell --file ./set_environment.ps1 | |
# | |
function set_env ($name, $text, $scope="User") { | |
(getRegistryKey $scope).SetValue($name, $text, [Microsoft.Win32.RegistryValueKind]::ExpandString) | |
} | |
function del_env ($name, $scope="User") { | |
(getRegistryKey $scope).DeleteValue($name) | |
} | |
function get_env ($name, $scope="User") { | |
return (getRegistryKey $scope).GetValue( | |
$name, $null, | |
[Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames | |
) | |
} | |
function getRegistryKey($scope="User") { | |
switch ($scope.ToLower()) { | |
user { return [Microsoft.Win32.RegistryKey]::OpenBaseKey( | |
[Microsoft.Win32.RegistryHive]::CurrentUser, | |
[Microsoft.Win32.RegistryView]::Default | |
).OpenSubKey('Environment', $true) | |
} | |
machine { return [Microsoft.Win32.RegistryKey]::OpenBaseKey( | |
[Microsoft.Win32.RegistryHive]::LocalMachine, | |
[Microsoft.Win32.RegistryView]::Default | |
).OpenSubKey('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', $true) | |
} | |
default { throw 'getRegistryKey: Scope parameter should be either "Machine" or "User"' } | |
} | |
} | |
function initMachineEnvironment() { | |
set_env 00_path_windows "%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0" Machine | |
set_env 01_path_my_packages "%ProgramData%\scoop\shims;%ProgramData%\chocolatey\bin" Machine | |
set_env 99_path_backup_values "%ProgramFiles(x86)%\NVIDIA Corporation\PhysX\Common" Machine | |
set_env ChocolateyInstall "%ProgramData%\chocolatey" Machine | |
set_env JAVA_HOME "%ProgramFiles%\Java\jdk1.8.0_121" Machine | |
set_env Path "%00_path_windows%;%01_path_my_packages%;%JAVA_HOME%;%ProgramFiles%\Docker\Docker\Resources\bin" Machine | |
set_env PSModulePath "%ProgramFiles%\WindowsPowerShell\Modules;%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules" Machine | |
set_env SCOOP_GLOBAL "%ProgramData%\scoop" Machine | |
} | |
function initUserEnvironment() { | |
[Environment]::SetEnvironmentVariable("OneDrive", "e:\OneDrive", "User") | |
[Environment]::SetEnvironmentVariable("OneDrive_Home", "e:\OneDrive", "User") | |
[Environment]::SetEnvironmentVariable("Dropbox_Home", "e:\Dropbox", "User") | |
[Environment]::SetEnvironmentVariable("MSYS", "c:\tools\msys64", "User") | |
[Environment]::SetEnvironmentVariable("Cmder_Root", "c:\tools\cmder", "User") | |
[Environment]::SetEnvironmentVariable("Git", "c:\tools\git-sdk-64", "User") # "%00_MSYS%\usr\bin" User | |
# set_env 00_SCOOP "%Userprofile%\scoop" User | |
# set_env 01_GIT "c:\tools\git-sdk-64" User # "%00_MSYS%\usr\bin" User | |
set_env SCOOP "%Userprofile%\scoop" User | |
set_env 01_path_cmder "%Cmder_Root%;%Cmder_Root%\bin;%Cmder_Root%\vendor\conemu-maximus5;%Cmder_Root%\vendor\conemu-maximus5\ConEmu" User | |
set_env 01_path_git "%Git%;%Git%\usr\bin" User | |
set_env 02_path_perl "%Scoop%\apps\perl\current\c\bin;%Scoop%\apps\perl\current\perl\bin;%Scoop%\apps\perl\current\perl\site\bin" User | |
set_env 03_path_node "%Scoop%\apps\nvm\current\nodejs;%LocalAppData%\Yarn\config\global\node_modules\.bin" User | |
set_env 04_path_msys "%ChocolateyInstall%\lib\msys2;%MSYS%;%MSYS%\usr\bin" User | |
set_env 99_path_other "%AppData%\Boxstarter;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps" User | |
set_env Choco "%ChocolateyInstall%" User | |
# set_env CMDER_ROOT "c:\tools\cmder" User | |
set_env ConEmuDir "%Cmder_Root%\vendor\conemu-maximus5" User | |
# set_env DROPBOX_HOME "E:\Dropbox" User | |
# set_env GIT "%01_GIT%" User | |
set_env Git_Install_Root "%Git%" User # set_env GIT_INSTALL_ROOT__ "%00_SCOOP%\apps\git-with-openssh\current" | |
# set_env GIT_SSH__ "%GIT_INSTALL_ROOT%\usr\bin\ssh.exe" User | |
# set_env MSYS "%00_MSYS%" User | |
set_env NVM_HOME "%Scoop%\apps\nvm\current" User | |
set_env NVM_SYMLINK "%Scoop%\apps\nvm\current\nodejs" User | |
set_env ONEDRIVE_HOME "%OneDrive%" User | |
set_env Path "%Scoop%\shims;%Userprofile%\bin;%01_path_cmder%;%01_path_git%;%02_path_perl%;%03_path_node%;%04_path_msys%;%OneDrive%\01_portable_apps;%99_path_other%" User | |
set_env PHP_INI_SCAN_DIR "%laragon%\bin\php\current\ext" User | |
set_env PSModulePath "%UserProfile%\Documents\WindowsPowerShell\Modules;%Appdata%\Boxstarter" User | |
# set_env SCOOP "%Userprofile%\scoop" User | |
set_env UBUNTU "%localappdata%\Lxss\rootfs" User | |
} | |
# init | |
initMachineEnvironment | |
initUserEnvironment | |
$env:Path -split ";" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment