Skip to content

Instantly share code, notes, and snippets.

@instance-id
Last active April 20, 2021 02:27
Show Gist options
  • Save instance-id/fb5c45c7ff099e2a15b869a0a1ad6451 to your computer and use it in GitHub Desktop.
Save instance-id/fb5c45c7ff099e2a15b869a0a1ad6451 to your computer and use it in GitHub Desktop.
Dev VM setup - still slightly WIP
# ------------------------------------------------- Dev PC Setup
# --------------------------------------------------------------
echo '-----------------------------'
echo 'Begin dev environment setup: '
echo '-----------------------------'
Update-ExecutionPolicy Unrestricted
# -------------------------------- Check for 10gb network adapter
$networkAdapter = Get-NetAdapter -InterfaceDescription 'Red Hat*' -ErrorAction SilentlyContinue | select -Property ifIndex
# --------------- If Virtio network adapter not present, install
# --------------------------------------------------------------
if ($null -eq $networkAdapter.ifIndex) {
# ----------------------------- Driver Certificate
# ------------------------------------------------
function AddCert {
$DriverPath = Get-Item 'D:\NetKVM\w10\amd64'
$CertStore = Get-Item 'cert:\LocalMachine\TrustedPublisher'
$CertStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
Get-ChildItem -Recurse -Path $DriverPath -Filter '*.cat' | % {
$Cert = (Get-AuthenticodeSignature $_.FullName).SignerCertificate
Write-Host ( 'Added {0}, {1} from {2}' -f $Cert.Thumbprint, $Cert.Subject, $_.FullName )
$CertStore.Add($Cert)
}
$CertStore.Close()
}
# -------------------- Add Cert for Silent Install
AddCert
$virtioPath = [System.IO.Path]::Combine('D:\', 'virtio-win-gt-x64.msi')
$virtioArgs = "/i ${virtioPath} /norestart /passive /lvx* install.log /qn ADDLOCAL=ALL"
Start-Process 'msiexec.exe' -arg $virtioArgs -Wait
} else { # TODO: Assign IP to 10gb NIC }
# ------------------------------------------- Install Chocolatey
if ($null -eq (Get-Command 'choco' -ErrorAction SilentlyContinue) ) {
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}
# ------------------------- Forces env variable update
function Invoke-RefreshEnvironment { RefreshEnv }
Invoke-RefreshEnvironment
# --------------------------------------------- WinGet Installer
if (!(Test-Path Microsoft.WindowsTerminal.msixbundle -PathType Leaf)) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$githubLatestReleases = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest'
$githubLatestRelease = (((Invoke-WebRequest $gitHubLatestReleases) | ConvertFrom-Json).assets.browser_download_url | select-string -Pattern 'appxbundle').Line
Invoke-WebRequest $githubLatestRelease -OutFile 'Microsoft.DesktopAppInstaller.appxbundle'
}
Add-AppxPackage -path .\Microsoft.DesktopAppInstaller.appxbundle
Invoke-RefreshEnvironment
# ------------------------------------------ Winget App Installs
winget install Microsoft.PowerShell-Preview
Invoke-RefreshEnvironment
# --------------------------------------------- Windows Features
# --------------------------------------------------------------
.\applysettings.ps1
pwsh.exe -File .\pc_setup.ps1
# ---------------------------------------------------- Set Theme
Set-ItemProperty 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Name AppsUseLightTheme -Value 0 -Force
Set-ItemProperty 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Name SystemUsesLightTheme -Value 0 -Force
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "CortanaEnabled" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "CanCortanaBeEnabled" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "DeviceHistoryEnabled" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "EnableProactive" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "SearchboxTaskbarMode" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "CortanaConsent" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "CortanaInAmbientMode" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "BingSearchEnabled" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "HistoryViewEnabled" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "AllowSearchToUseLocation" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Speech_OneCore\Preferences" -Name "VoiceActivationEnableAboveLockscreen" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name "DisableWebSearch" -PropertyType DWord -Value 1 -force | Out-Null;
New-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" -Name "ConnectedSearchUseWeb" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "CortanaEnabled" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "CanCortanaBeEnabled" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "DeviceHistoryEnabled" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "EnableProactive" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "SearchboxTaskbarMode" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "CortanaConsent" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "CortanaInAmbientMode" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "BingSearchEnabled" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "HistoryViewEnabled" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "AllowSearchToUseLocation" -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Speech_OneCore\Preferences" -Name "VoiceActivationEnableAboveLockscreen" -PropertyType DWord -Value 0 -force | Out-Null;
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' -Name 'TaskbarSmallIcons' -Type DWord -Value 1
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' -Name 'HideFileExt' -Type DWord -Value 0
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' -Name 'Hidden' -Type DWord -Value 1
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Type DWord -Value 1
#Disabling advertising info and device metadata collection for this machine
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo' -Name 'Enabled' -PropertyType DWord -Value 0 -force | Out-Null;
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Device Metadata' -Name 'PreventDeviceMetadataFromNetwork' -PropertyType DWord -Value 1 -force | Out-Null;
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{a0c69a99-21c8-4671-8703-7934162fcf1d}\PropertyBag' -Name 'ThisPCPolicy' -Value 'Hide' -Force | Out-Null;
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{35286a68-3c57-41a1-bbb1-0eae73d76c95}\PropertyBag' -Name 'ThisPCPolicy' -Value 'Hide' -Force | Out-Null;
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{0ddd015d-b06c-45d5-8c4c-f59713854639}\PropertyBag' -Name 'ThisPCPolicy' -Value 'Hide' -Force | Out-Null;
# ------------------------------------------------- Dev PC Setup
# --------------------------------------------------------------
echo '-----------------------------------------'
echo 'Dev environment configuration: Continued '
echo '-----------------------------------------'
Update-ExecutionPolicy Unrestricted
function Invoke-RefreshEnvironment { RefreshEnv }
Invoke-RefreshEnvironment
winget install Microsoft.WindowsTerminal
winget install Git.Git
winget install RStudio.RStudio
winget install Microsoft.VisualStudioCodeInsiders.System-x64
winget install Microsoft.ROpen
winget install Microsoft.PowerToys
winget install VMware.HorizonClient --override '/s /norestart /v\" /qn VDM_Server=<<REDACTED>>\"'
# ------------------------------------------------ Install Scoop
if ($null -eq (Get-Command 'scoop' -ErrorAction SilentlyContinue) ) {
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
}
scoop bucket add extras
scoop bucket add nerd-fonts
scoop install sudo
scoop install Delugia-Nerd-Font Delugia-Nerd-Font-Complete Cascadia-Code Cascadia-Mono Cascadia-MonoPL Cascadia-PL ubuntumono-nf ubuntu-nf inconsolata-nf firacode firacode-nf sourcecodepro-nf AnonymousPro-NF
scoop install oh-my-posh posh-git
scoop install shim sed psutils grep ngrok less gcc curl
Invoke-RefreshEnvironment
scoop install nu starship autohotkey
Invoke-RefreshEnvironment
scoop install vcredist2015 vcredist2019
Invoke-RefreshEnvironment
scoop install dotnet-core-sdk python dotnet-script github firefox python3
Invoke-RefreshEnvironment
# ------------------------------------------- PowerShell Gallery
# --------------------------------------------------------------
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
# Turn off People in Taskbar
If (-Not (Test-Path 'HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People')) {
New-Item -Path HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People | Out-Null
}
Set-ItemProperty -Path 'HKCU:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\People' -Name PeopleBand -Type DWord -Value 0
# ------------------------------- Configuring Windows Properties
# Show hidden files, Show protected OS files, Show file extensions
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions
# -------------------------------------------------- Remove Crap
# --------------------------------------------------------------
function Remove-WindowsApp {
Param ([string]$appName)
Write-Output "Trying to remove $appName"
Get-AppxPackage $appName -AllUsers | Remove-AppxPackage
Get-AppXProvisionedPackage -Online | Where-Object DisplayNam -like $appName | Remove-AppxProvisionedPackage -Online
}
# ----------------------------------- App removal list
$applicationList = @(
'Microsoft.Getstarted'
'*MarchofEmpires*'
'Microsoft.GetHelp'
'Microsoft.WindowsPhone'
'Microsoft.Office.Sway'
'Microsoft.ZuneMusic'
'Microsoft.ZuneVideo'
'*Autodesk*'
'*BubbleWitch*'
'king.com*'
'G5*'
'*Dell*'
'*Facebook*'
'*Keeper*'
'*Plex*'
'*.Duolingo-LearnLanguagesforFree'
'*.EclipseManager'
'ActiproSoftwareLLC.562882FEEB491' # Code Writer
'*.AdobePhotoshopExpress'
);
# ---------------------------------------- Remove apps
foreach ($app in $applicationList) { Remove-WindowsApp $app }
# ------------------------------------------------- System Setup
# --------------------------------------------------------------
&subst z: \\172.254.6.200\data\_share
$DOTROOT = "$(resolve-path 'Z:\.dotfiles')"
$RFILESDIR = [System.IO.Path]::Combine($DOTROOT, '.setup', 'files')
$FILESDIR = [System.IO.Path]::Combine($env:HOMEDRIVE, 'files')
$env:PATH += ";${FILESDIR}"
# ----------------------------- Create files directory
if (-not (Test-Path $FILESDIR)) { New-Item -Path $FILESDIR -ItemType Directory > $null }
# ----------------------------------- Copy executables
$RFILESDIR | gci | % { Copy-Item -Path $_ -Destination $FILESDIR -Force }
# ------------------------------------------- Install PS Modules
# --------------------------------------------------------------
Install-Module -Name 'PSReadLine'
Install-Module -Name 'PSFzf'
Install-Module -Name 'PoshRSJob'
Install-Module -Name 'AdvancedHistory'
# ------------------------------------------------- Pwsh Profile
# --------------------------------------------------------------
$pwshProfile = @'
$DOTROOT = "$(resolve-path 'Z:\.dotfiles')"
$DOTPWSH = [System.IO.Path]::Combine($DOTROOT, '.pwsh')
$pwshProfile = [System.IO.Path]::Combine($DOTPWSH, 'pwsh_profile.ps1')
. $pwshProfile
'@
$pwshProfile > $PROFILE
$pwshProPath = 'C:\Users\User\Documents\PowerShell\Microsoft.PowerShell_profile.ps1'
if (-not (Test-Path $pwshProPath)) { New-Item -Path $pwshProPath -ItemType File -Force > $null }
$pwshProfile > $pwshProPath
# ------------------------------------------------ Install Fonts
# --------------------------------------------------------------
$fontPath = [System.IO.Path]::Combine('Z:\', '_fonts'); Set-Location $fontPath; foreach ($font in Get-ChildItem -Path "${fontPath}\*.ttf" -Recurse -File) { .\Add-Font.ps1 $font }
# ------------------------------------ Windows Terminal settings
# --------------------------------------------------------------
$WTROOT = [System.IO.Path]::Combine($DOTROOT, '.wt')
$wtsettingsPath = "${WTROOT}\settings.json"
$wtDefault = 'C:\Users\User\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json'
$wtSettings = $(cat "${WTROOT}\settings.json")
$wtSettings > $wtDefault
# ---------------------------------------------- VSCode Insiders
# --------------------------------------------------------------
$VSCROOT = [System.IO.Path]::Combine($DOTROOT, '.vscode-insiders')
$VSCDATA = [System.IO.Path]::Combine($env:APPDATA, 'Code - Insiders')
$VSCEXT = [System.IO.Path]::Combine($HOME, '.vscode-insiders')
code-insiders --install-extension Shan.code-settings-sync
code-insiders --install-extension gabrielgrinberg.auto-run-command
New-Item -Path $VSCEXT -ItemType File -Name '.firstRun'
Copy-Item -Path "${VSCROOT}/theme_ext/instance-id.turnip-0.1.1" -Destination "${VSCEXT}/extensions" -Recurse -Force
Copy-Item -Path "${VSCROOT}/settings.json" -Destination "${VSCDATA}/User/" -Force
Copy-Item -Path "${VSCROOT}/syncLocalSettings.json" -Destination "${VSCDATA}/User/" -Force
&code-insiders $VSCEXT
$codeExe = 'Code - Insiders.exe'
$codePath = "$env:programfiles\Microsoft VS Code Insiders\"
$ide = [System.IO.Path]::Combine($codePath, $codeExe)
# ---------------------------------------------------- VPN Setup
# --------------------------------------------------------------
$vmFiles = [System.IO.Path]::Combine('Z:\', 'VM_Files')
$vpnInstaller = 'anyconnect-win-4.9.04053-core-vpn-predeploy-k9.msi'
$vpnPath = [System.IO.Path]::Combine($vmFiles , $vpnInstaller)
$vpnArgs = "/i ${vpnPath} /norestart /passive /lvx* install.log"
Start-Process 'msiexec.exe' -arg $vpnArgs -Wait
$vpnProfile = 'C:\ProgramData\Cisco\Cisco AnyConnect Secure Mobility Client\Profile'
$vpnProPath = [System.IO.Path]::Combine($vmFiles, 'any_connect_profile')
if (!(Test-Path -Path $vpnProfile)) { New-Item -Path $vpnProfile -ItemType Directory }
Copy-Item -Path "${vpnProPath}\*" -Destination $vpnProfile -Recurse
# ------------------------------------------------- Associations
# --------------------------------------------------------------
function Set-FileAssociation {
param(
[string[]] $extensions,
[string] $executable
)
echo '## setting up file associations'
foreach ($ext in $extensions) {
$extfile = $ext + 'file'
$dotext = '.' + $ext
cmd /c assoc $dotext=$extfile
cmd /c "ftype $extfile=""${executable}"" ""%1"""
echo ''
}
}
$exts = @('cs', 'css', 'csv', 'csproj', 'gitignore', 'go', 'html', 'js', 'json', 'jsonc', 'json5', 'log', 'md', 'patch', 'ps1', 'psd1', 'psm1', 'py', 'sh', 'sql', 'toml', 'txt', 'xml', 'yml', 'yaml', 'zsh')
$ide = "$env:programfiles\Microsoft VS Code Insiders\Code - Insiders.exe"
Set-FileAssociation -extensions $exts -executable "${ide}"
# ---------------------------------------------- AHK Association
$exts = @('ahk')
$ahk = 'C:\Users\User\scoop\apps\autohotkey\1.1.33.06\AutoHotkeyU64.exe'
Set-FileAssociation -extensions $exts -executable "${ahk}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment