forked from joymon/win10-dev-box-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetupDeveloperMachine.ps1
372 lines (331 loc) · 15.1 KB
/
SetupDeveloperMachine.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
param ($RunScript=$True)
function Run {
InstallPrerequisites
ConfigureEnvironment
InstallWindowsSubsystemForLinux
InstallPrograms
ConfigureDevelopmentTools
CleanUp
RunWindowsUpdate
AddBoxstarterDoneRestorePoint
SetGitUser
#InstallAndConfigureWireguard
#CloneAllGitlabRepositories
OpenManualInstructions
}
$GitCloneTarget = "C:\dev"
$ChocolateyCacheFolder = "C:\choco-temp"
function InstallPrerequisites {
if (Check-Command -cmdname 'choco') {
Write-Host "Choco is already installed, skip installation."
}
else {
Write-Host "Installing Chocolatey first..."
Write-Host "------------------------------------"
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Write-Host "Installed Chocolatey" -ForegroundColor Green
}
if (Check-Command -cmdname 'Install-BoxstarterPackage') {
Write-Host "Boxstarter is already installed, skip installation."
}
else {
Write-Host "Installing Boxstarter..."
Write-Host "------------------------------------"
. { iwr -useb https://boxstarter.org/bootstrapper.ps1 } | iex; Get-Boxstarter -Force
Write-Host "Installed Boxstarter" -ForegroundColor Green
}
if (Check-Command -cmdname 'scoop') {
Write-Host "scoop is already installed, skip installation."
}
else {
Write-Host "Installing scoop..."
Write-Host "------------------------------------"
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
Write-Host "Installed scoop" -ForegroundColor Green
}
refreshenv
}
function ConfigureEnvironment {
if (!(Test-Path $ChocolateyCacheFolder)) {
mkdir $ChocolateyCacheFolder
}
choco config set cacheLocation "$ChocolateyCacheFolder"
Update-ExecutionPolicy Unrestricted
Enable-ComputerRestore -Drive "C:\"
vssadmin list shadowstorage
vssadmin resize shadowstorage /on=C: /for=C: /maxsize=10%
Set-ItemProperty "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name SystemRestorePointCreationFrequency -Value 5
if (!((Get-ComputerRestorePoint).Description -Like "Clean Install")) {
Checkpoint-Computer -Description "Clean Install"
}
Write-Host "Setting up power options"
Powercfg /Change monitor-timeout-ac 20
Powercfg /Change standby-timeout-ac 0
powercfg -setacvalueindex scheme_current sub_buttons pbuttonaction 0
Write-Host "Completed power options" -Foreground green
# Show hidden files, Show protected OS files, Show file extensions
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowTaskViewButton -Value 0 -Type DWord -Force
Set-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowCortanaButton -Value 0 -Type DWord -Force
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search -Name SearchBoxTaskbarMode -Value 0 -Type DWord -Force
# Remove all $AppNames String array from taskbar Pin location
$ComObj = (New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}')
$AppNames = "Microsoft Edge|stor|mai|support"
#use the match to limit the apps removed from start tiles
$ComObjItem = $ComObj.Items() | ?{$_.Name -match $AppNames}
foreach ($Obj in $ComObjItem) {
Write-Host "$("Checking " + $Obj.name)" -ForegroundColor Cyan
foreach ($Verb in $Obj.Verbs()) {
Write-Host "$("Verb: " + $Verb.name)" -ForegroundColor white
if (($Verb.name -match 'Un.*pin from Start')) {
Write-Host "$("Ok " + $Obj.name + " contains " + $Verb.name)" -ForegroundColor Red
try {
$Verb.DoIt()
} catch {}
}
if (($Verb.name -match 'Un.*pin from tas&kbar') -And ($Obj.name -match $AppNames)) {
Write-Host "$("Ok " + $Obj.name + " contains " + $Verb.name)" -ForegroundColor Red
try {
$Verb.DoIt()
} catch {}
}
}
}
Write-Host "Remove pre-installed apps"
# Microsoft junk
Get-AppxPackage Microsoft.*3D* | Remove-AppxPackage
Get-AppxPackage Microsoft.*advertising* | Remove-AppxPackage
Get-AppxPackage Microsoft.Bing* | Remove-AppxPackage
Get-AppxPackage Microsoft.CommsPhone | Remove-AppxPackage
Get-AppxPackage Microsoft.Getstarted | Remove-AppxPackage
Get-AppxPackage Microsoft.Messaging | Remove-AppxPackage
Get-AppxPackage Microsoft.MicrosoftOfficeHub | Remove-AppxPackage
Get-AppxPackage Microsoft.MicrosoftStickyNotes | Remove-AppxPackage
Get-AppxPackage Microsoft.Office.OneNote | Remove-AppxPackage
Get-AppxPackage Microsoft.Office.Sway | Remove-AppxPackage
Get-AppxPackage Microsoft.OneConnect | Remove-AppxPackage
Get-AppxPackage Microsoft.People | Remove-AppxPackage
Get-AppxPackage Microsoft.SkypeApp | Remove-AppxPackage
Get-AppxPackage Microsoft.Wallet | Remove-AppxPackage
Get-AppxPackage Microsoft.Windows.Photos | Remove-AppxPackage
Get-AppxPackage Microsoft.WindowsAlarms | Remove-AppxPackage
Get-AppxPackage Microsoft.WindowsFeedbackHub | Remove-AppxPackage
Get-AppxPackage Microsoft.WindowsMaps | Remove-AppxPackage
Get-AppxPackage Microsoft.WindowsPhone | Remove-AppxPackage
Get-AppxPackage Microsoft.WindowsSoundRecorder | Remove-AppxPackage
Get-AppxPackage microsoft.windowscommunicationsapps | Remove-AppxPackage
Get-AppxPackage Microsoft.Zune* | Remove-AppxPackage
Get-AppxPackage Microsoft.ScreenSketch | Remove-AppxPackage
Get-AppxPackage Microsoft.YourPhone | Remove-AppxPackage
# Misc
Get-AppxPackage *Autodesk* | Remove-AppxPackage
Get-AppxPackage *Spotify* | Remove-AppxPackage
# Junk games
Get-AppxPackage king.com.* | Remove-AppxPackage
Get-AppxPackage *disney* | Remove-AppxPackage
Get-AppxPackage *MarchofEmpires* | Remove-AppxPackage
Get-AppxPackage *Solitaire* | Remove-AppxPackage
Write-Host "Removed pre-installed apps"
$WallpaperImagePath = "$([Environment]::GetFolderPath("MyDocuments"))/wallpaper.jpg"
if(!((Get-ItemProperty -path "HKCU:Control Panel\Desktop" -name WallPaper).WallPaper -Like $WallpaperImagePath)) {
(new-object net.webclient).DownloadFile("https://unsplash.com/photos/eMBdLhYY468/download?force=true", $WallpaperImagePath)
Set-ItemProperty -path "HKCU:Control Panel\Desktop" -name WallPaper -value $WallpaperImagePath
Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name TileWallpaper -value "0"
$SpanWallpaper = "22";
Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name WallpaperStyle -value $SpanWallpaper -Force
Invoke-Reboot
}
}
function InstallWindowsSubsystemForLinux {
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
refreshenv
wsl --set-default-version 2
wsl --update
if (!((wsl --list --all) -Like "*Ubuntu*")) {
wsl --install --distribution Ubuntu
}
}
function InstallPrograms {
Write-Host "Installing programs using choco or scoop"
choco install poshgit -y
choco install divvy -y
choco install microsoft-edge -y
choco install googlechrome -y
choco install firefox -y
choco install obs-studio -y
choco install vscode -y
choco install nvm -y
choco install lastpass -y
choco install slack -y
choco install greenshot -y
choco install azure-data-studio -y
choco install microsoft-windows-terminal -y
choco install firacode -y
choco install dotnetcore -y
choco install jetbrains-rider -y
choco install lastpass -y
choco install ssms -y
choco install docker-desktop -y
choco install dotnetcore-sdk -y
choco install spotify -y
scoop install yarn
scoop install sudo
scoop install pwsh
Write-Host "Installed programs" -Foreground green
}
function ConfigureDevelopmentTools {
Write-Host "Installing VS Code extensions"
code --install-extension dbaeumer.vscode-eslint
code --install-extension esbenp.prettier-vscode
code --install-extension formulahendry.auto-rename-tag
code --install-extension hbenl.vscode-test-explorer
code --install-extension hbenl.vscode-test-explorer-liveshare
code --install-extension kavod-io.vscode-jest-test-adapter
code --install-extension ms-vsliveshare.vsliveshare
code --install-extension msjsdiag.debugger-for-chrome
code --install-extension PKief.material-icon-theme
code --install-extension runningcoder.react-snippets
code --install-extension schmas.jump-to-tests
code --install-extension sandcastle.vscode-open
Write-Host "Installed VS Code Extensions" -Foreground green
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name z -RequiredVersion 1.1.10 -AllowClobber
Install-Module psreadline -Force
Add-ToPowerShellProfile -Find "*Set-PSReadLineOption*" -Content @("
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
")
git config --global push.default current
git config --global core.editor "code --wait"
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'
git config --global mergetool.keepBackup false
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
git config --global alias.co "checkout"
git config --global alias.oops "commit --amend --no-edit"
git config --global alias.a "add --patch"
git config --global alias.please "push --force-with-lease"
git config --global alias.navigate "!git add . && git commit -m 'WIP-mob' --allow-empty --no-verify && git push -u --no-verify"
git config --global alias.drive "!git pull --rebase && git log -1 --stat && git reset HEAD^ && git push --force-with-lease"
git config --global pull.rebase true
git config --global alias.r "!git fetch; git rebase origin/master -i --autosquash"
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
git config --global alias.mr "push -u -o merge_request.create -o merge_request.remove_source_branch"
if (!(Test-Path $GitCloneTarget)) {
mkdir $GitCloneTarget
}
}
function CleanUp {
Write-Host "Cleaning desktop"
Remove-Item C:\Users\*\Desktop\*lnk
Remove-Item C:\Users\*\Desktop\desktop.ini -Force
Write-Host "Desktop cleaned"
}
function RunWindowsUpdate {
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name PSWindowsUpdate -Repository PSGallery
Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d -AddServiceFlag 7
Get-WindowsUpdate
Install-WindowsUpdate
}
function AddBoxstarterDoneRestorePoint {
if (!((Get-ComputerRestorePoint).Description -Like "Boxstarter done")) {
Checkpoint-Computer -Description "Boxstarter done"
}
}
function SetGitUser {
$GitUserName = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GIT_USER_NAME", "User")
$GitEmail = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GIT_EMAIL", "User")
if($GitUserName -and $GitEmail) {
git config --global user.name "$GitUserName"
git config --global user.email "$GitEmail"
}
}
function InstallAndConfigureWireguard {
$WireGuardConfigPath = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_WIREGUARD_CONFIG_PATH", "User")
if($WireGuardConfigPath -and (Test-Path $WireGuardConfigPath)) {
choco install wireguard -y
refreshenv
if(!((wg show) -like "*interface: *")) {
wireguard /installtunnelservice "$WireGuardConfigPath"
Invoke-Reboot
}
}
}
function CloneAllGitlabRepositories {
$GitlabBaseUrl = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GITLAB_BASE_URL", "User")
$GitlabToken = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GITLAB_TOKEN", "User")
$GitlabGroupId = [Environment]::GetEnvironmentVariable("WIN10_DEV_BOX_GITLAB_GROUP_ID", "User")
if ($GitlabBaseUrl -and $GitlabToken) {
if (!(Test-Path $GitCloneTarget)) {
mkdir $GitCloneTarget
}
Push-Location $GitCloneTarget
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Page = 0
do {
$Page = $Page + 1
$Url="$GitlabBaseUrl/api/v4/groups/$GitlabGroupId/projects?page=$($Page)&per_page=100&include_subgroups=true&private_token=$GitlabToken"
$Request = Invoke-WebRequest $Url | ConvertFrom-Json
$ProjectCount = $Request.Count
Write-Host "Page $Page Count $ProjectCount"
foreach ($Project in $Request) {
if ($Project.archived) {
Write-Host "Skip $($Project.name_with_namespace), archived"
} elseif(Test-Path "$GitCloneTarget/$($Project.path)") {
Write-Host "Skip $($Project.name_with_namespace), already cloned"
} else {
Write-Host "git clone $($Project.ssh_url_to_repo)"
git clone $($Project.ssh_url_to_repo)
}
}
} while ($ProjectCount -gt 0)
} finally {
Pop-Location
}
}
}
function OpenManualInstructions {
$ManualInstructionsFilePath = "$([Environment]::GetFolderPath("Desktop"))/ManualSteps.txt";
if (!(Test-Path $ManualInstructionsFilePath)) {
"Manual steps
Manual installs
MicSwitch https://github.com/iXab3r/MicSwitch/releases
LogiCapture https://www.logitech.com/en-us/product/capture
choco install clipx -y
Configure ClipX
1. Right click tray icon and open settings
2. Check ""Run ClipX on Startup""
3. Remember the last 256 entries
4. Delete hotkeys ""Navigate"" and ""Google Search""
Configure VSCode
1. Turn on Settings Sync (Ctrl+P ""Turn On"")
2. Log in with Github
3. ""Replace Local""
Add saved Powershell_profile.ps1
Add saved Windows Terminal settings.json" | Add-Content $ManualInstructionsFilePath -Encoding UTF8
}
notepad.exe $ManualInstructionsFilePath
}
#### -> HELPER FUNCTIONS ####
function Check-Command($cmdname) {
return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue)
}
function Add-ToPowerShellProfile($Find, $Content) {
if (!( Test-Path $Profile )) {
New-Item $Profile -Type File -Force
} else {
$CurrentProfileContent = Get-Content $Profile
}
if (!($CurrentProfileContent -Like $Find)) {
$Content | Add-Content $Profile -Encoding UTF8
}
}
#### <- HELPER FUNCTIONS ####
if($RunScript) {
Run
}