Skip to content

Instantly share code, notes, and snippets.

@fearthecowboy
Created July 9, 2020 17:13
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 fearthecowboy/fb5a8d69599678924839fb3481b073df to your computer and use it in GitHub Desktop.
Save fearthecowboy/fb5a8d69599678924839fb3481b073df to your computer and use it in GitHub Desktop.
Set-ExecutionPolicy -Scope LocalMachine Unrestricted -force
$ProgressPreference=0
function ResolvePath {
param (
[string] $FileName
)
$FileName = Resolve-Path $FileName -ErrorAction SilentlyContinue `
-ErrorVariable _frperror
if (-not($FileName)) {
$FileName = $_frperror[0].TargetObject
}
return $FileName
}
function In($location, $scriptblock) {
pushd $location
try {
& $scriptblock
} finally {
popd
}
}
function write-hostcolor { Param ( $color, [parameter(ValueFromRemainingArguments=$true)] $content ) write-host -fore $color $content }
function comment { Param ( [parameter(ValueFromRemainingArguments=$true)] $content ) write-host -fore darkgray $content }
function action { Param ( [parameter(ValueFromRemainingArguments=$true)] $content ) write-host -fore green $content }
function warn { Param ( [parameter(ValueFromRemainingArguments=$true)] $content ) write-host -fore yellow $content }
function err { Param ( [parameter(ValueFromRemainingArguments=$true)] $content ) write-host -fore red $content }
new-alias '//' comment
new-alias '/#' comment
new-alias '=>' action
new-alias '/$' warn
new-alias '/!' err
function mysplit-path($path) {
return ($path.split(";",[StringSplitOptions]::RemoveEmptyEntries) |% { $_.trim("\").Trim() })
}
function Update-PathFromRegistry {
$cur = (mysplit-path $env:path)
$u = mysplit-path ([System.Environment]::GetEnvironmentVariable( "path", 'User'))
$cur = $cur + @(compare-object $cur $u |? { $_.SideIndicator -eq "=>" } |% {$_.InputObject })
$m = mysplit-path ([System.Environment]::GetEnvironmentVariable( "path", 'Machine'))
$cur = @(compare-object $cur $m |? { $_.SideIndicator -eq "=>" } |% {$_.InputObject }) + $cur
$env:path = $cur -join ";"
}
function Diff-PathFromRegistry {
$u = ([System.Environment]::GetEnvironmentVariable( "path", 'User'))
$m = ([System.Environment]::GetEnvironmentVariable( "path", 'Machine'))
$newPath = "$m;$u"
$np = $newpath.split(";") |% { $_.trim("\").Trim() }
$op = $env:path.split(";") |% { $_.trim("\").Trim() }
diff $np $op
}
function Reset-PathFromRegistry {
write-host -fore darkcyan " Reloading Path From Registry."
$u = ([System.Environment]::GetEnvironmentVariable( "path", 'User'))
$m = ([System.Environment]::GetEnvironmentVariable( "path", 'Machine'))
$newPath = "$m;$u"
$env:path = $newPath
}
function Get-EnvironmentFromRegistry($key) {
if( $key ) {
$u = ([System.Environment]::GetEnvironmentVariable( $key, 'User'))
$m = ([System.Environment]::GetEnvironmentVariable( $key, 'Machine'))
} else {
$u = ([System.Environment]::GetEnvironmentVariables( 'User'))
$m = ([System.Environment]::GetEnvironmentVariables( 'Machine'))
}
$uservars = $u.keys |% { "$_=$($u[$_])" }
$machinevars = $m.keys |% { "$_=$($m[$_])" }
$e = dir env: |%{ "$($_.key)=$($_.value)" }
return $uservars + $machinevars
}
/# Make temp folder
$shh = mkdir -ea 0 c:\tmp
$shh = cd c:\tmp
/# Install VSCode
iwr https://aka.ms/win32-x64-user-stable -outfile vscode.exe
.\vscode.exe /silent /force /verysilent /suppressmsgboxes | Out-Null
(get-process *edge*).Kill()
(get-process code).Kill()
/# Install Git
iwr https://github.com/git-for-windows/git/releases/download/v2.27.0.windows.1/Git-2.27.0-64-bit.exe -outfile git.exe
.\git.exe /silent /force | Out-Null
/# Update Path
Update-PathFromRegistry
/# Install VSCode Extensions
code --install-extension ms-vscode.csharp | Out-Null
code --install-extension ms-vscode.powershell | Out-Null
/# Install NVS
$env:NVS_HOME="$env:LOCALAPPDATA\nvs"
git clone https://github.com/jasongin/nvs "$env:NVS_HOME"
. "$env:NVS_HOME\nvs.ps1" install
/# Update Path
Update-PathFromRegistry
/# Install Node LTS
nvs add 14
nvs link 14
/# Update Path
Update-PathFromRegistry
/# Install PWSH, dotnet, autorest@beta
npm install -g pwsh
/# fix console settings
set-content -path console.reg -value 'Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Console]
"WindowSize"=dword:003c00a0
"FontSize"=dword:00180000
"FontFamily"=dword:00000036
"FontWeight"=dword:00000190
"FaceName"="Lucida Console"
"InterceptCopyPaste"=dword:00000000
"ScreenBufferSize"=dword:232900a0
"WindowAlpha"=dword:000000f2
"ColorTable00"=dword:001e1401
[HKEY_CURRENT_USER\Console\%SystemRoot%_system32_WindowsPowerShell_v1.0_PowerShell.exe]
"ColorTable00"=dword:00281400
[HKEY_CURRENT_USER\Console\%SystemRoot%_system32_bash.exe]
"ColorTable00"=dword:00142800'
regedit /s /q .\console.reg
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\PowerShell.lnk")
$Shortcut.TargetPath = (pwsh -command '(get-process pwsh).path')
$Shortcut.Save()
# pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment