Last active
February 27, 2019 17:35
-
-
Save fearthecowboy/7e4b8756b5299bca47dba2f5c94eee2c to your computer and use it in GitHub Desktop.
Setup Test Sandbox for AutoRest
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
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.20.1.windows.1/Git-2.20.1-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 10.15.1 | |
nvs link 10.15.1 | |
/# Update Path | |
Update-PathFromRegistry | |
/# Install PWSH, dotnet, autorest@beta | |
npm install -g pwsh | |
npm install -g dotnet-sdk-2.1 | |
npm install -g autorest@beta | |
/# force the nuget cache to build now | |
dotnet build | |
/# Add .net to path | |
$dotnetsdk = which-dotnet | |
setx PATH "$dotnetsdk;$ENV:PATH" | |
/# Update Path | |
Update-PathFromRegistry | |
/# 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