Last active
December 5, 2018 23:19
-
-
Save mjfusa/67a59971db0990e5361fd55bba339d7a to your computer and use it in GitHub Desktop.
Chocolatey Install for new PC
This file contains 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
:checkPrivileges | |
NET FILE 1>NUL 2>NUL | |
if '%errorlevel%' == '0' ( goto continue | |
) else ( powershell "saps -filepath %0 -verb runas" >nul 2>&1) | |
exit /b | |
:continue | |
cd %~dp0 | |
powershell Set-ExecutionPolicy bypass -force | |
powershell -f setpath.ps1 | |
powershell Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) | |
for %%a in (7zip.install, googlechrome, vscode, git, visualstudio2017enterprise) do choco install %%a -y | |
:end |
This file contains 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
function Add-EnvPath { | |
param( | |
[Parameter(Mandatory=$true)] | |
[string] $Path, | |
[ValidateSet('Machine', 'User', 'Session')] | |
[string] $Container = 'Session' | |
) | |
if ($Container -ne 'Session') { | |
$containerMapping = @{ | |
Machine = [EnvironmentVariableTarget]::Machine | |
User = [EnvironmentVariableTarget]::User | |
} | |
$containerType = $containerMapping[$Container] | |
$persistedPaths = [Environment]::GetEnvironmentVariable('Path', $containerType) -split ';' | |
if ($persistedPaths -notcontains $Path) { | |
$persistedPaths = $persistedPaths + $Path | where { $_ } | |
[Environment]::SetEnvironmentVariable('Path', $persistedPaths -join ';', $containerType) | |
} | |
} | |
$envPaths = $env:Path -split ';' | |
if ($envPaths -notcontains $Path) { | |
$envPaths = $envPaths + $Path | where { $_ } | |
$env:Path = $envPaths -join ';' | |
} | |
} | |
function Remove-EnvPath { | |
param( | |
[Parameter(Mandatory=$true)] | |
[string] $Path, | |
[ValidateSet('Machine', 'User', 'Session')] | |
[string] $Container = 'Session' | |
) | |
if ($Container -ne 'Session') { | |
$containerMapping = @{ | |
Machine = [EnvironmentVariableTarget]::Machine | |
User = [EnvironmentVariableTarget]::User | |
} | |
$containerType = $containerMapping[$Container] | |
$persistedPaths = [Environment]::GetEnvironmentVariable('Path', $containerType) -split ';' | |
if ($persistedPaths -contains $Path) { | |
$persistedPaths = $persistedPaths | where { $_ -and $_ -ne $Path } | |
[Environment]::SetEnvironmentVariable('Path', $persistedPaths -join ';', $containerType) | |
} | |
} | |
$envPaths = $env:Path -split ';' | |
if ($envPaths -contains $Path) { | |
$envPaths = $envPaths | where { $_ -and $_ -ne $Path } | |
$env:Path = $envPaths -join ';' | |
} | |
} | |
function Get-EnvPath { | |
param( | |
[Parameter(Mandatory=$true)] | |
[ValidateSet('Machine', 'User')] | |
[string] $Container | |
) | |
$containerMapping = @{ | |
Machine = [EnvironmentVariableTarget]::Machine | |
User = [EnvironmentVariableTarget]::User | |
} | |
$containerType = $containerMapping[$Container] | |
[Environment]::GetEnvironmentVariable('Path', $containerType) -split ';' | | |
where { $_ } | |
} | |
Add-EnvPath -Path $PWD -Container 'Machine' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment