-
Notifications
You must be signed in to change notification settings - Fork 2
/
windows.ps1
425 lines (334 loc) · 14 KB
/
windows.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<#
#OPTIONAL
[Environment]::SetEnvironmentVariable("BoxStarter:DataDrive", "C", "Machine") # for reboots
[Environment]::SetEnvironmentVariable("BoxStarter:DataDrive", "C", "Process") # for right now
[Environment]::SetEnvironmentVariable("BoxStarter:SourceCodeFolder", "VSO", "Machine") # relative path to for reboots
[Environment]::SetEnvironmentVariable("BoxStarter:SourceCodeFolder", "VSO", "Process") # for right now
#START
START http://boxstarter.org/package/nr/url?http://boxstarter.org/package/nr/url?https://raw.githubusercontent.com/AddedInnovation/developer-setup/master/windows.ps1
Older version
START http://boxstarter.org/package/nr/url?https://raw.githubusercontent.com/AddedInnovation/developer-setup/fa49b39ccdd5b1b22af891f293af1a90272a11d3/windows.ps1
#>
$Boxstarter.RebootOk = $true
$Boxstarter.NoPassword = $false
$Boxstarter.AutoLogin = $true
$checkpointPrefix = 'BoxStarter:Checkpoint:'
function Get-CheckpointName {
param
(
[Parameter(Mandatory = $true)]
[string]
$CheckpointName
)
return "$checkpointPrefix$CheckpointName"
}
function Set-Checkpoint {
param
(
[Parameter(Mandatory = $true)]
[string]
$CheckpointName,
[Parameter(Mandatory = $true)]
[string]
$CheckpointValue
)
$key = Get-CheckpointName $CheckpointName
[Environment]::SetEnvironmentVariable($key, $CheckpointValue, "Machine") # for reboots
[Environment]::SetEnvironmentVariable($key, $CheckpointValue, "Process") # for right now
}
function Get-Checkpoint {
param
(
[Parameter(Mandatory = $true)]
[string]
$CheckpointName
)
$key = Get-CheckpointName $CheckpointName
[Environment]::GetEnvironmentVariable($key, "Process")
}
function Clear-Checkpoints {
$checkpointMarkers = Get-ChildItem Env: | where { $_.name -like "$checkpointPrefix*" } | Select -ExpandProperty name
foreach ($checkpointMarker in $checkpointMarkers) {
[Environment]::SetEnvironmentVariable($checkpointMarker, '', "Machine")
[Environment]::SetEnvironmentVariable($checkpointMarker, '', "Process")
}
}
function Use-Checkpoint {
param(
[string]
$CheckpointName,
[string]
$SkipMessage,
[scriptblock]
$Function
)
$checkpoint = Get-Checkpoint -CheckpointName $CheckpointName
if (-not $checkpoint) {
$Function.Invoke($Args)
Set-Checkpoint -CheckpointName $CheckpointName -CheckpointValue 1
}
else {
Write-BoxstarterMessage $SkipMessage
}
}
function Get-OSInformation {
$osInfo = Get-WmiObject -class Win32_OperatingSystem `
| Select-Object -First 1
return ConvertFrom-String -Delimiter \. -PropertyNames Major, Minor, Build $osInfo.version
}
function Test-IsOSWindows10 {
$osInfo = Get-OSInformation
return $osInfo.Major -eq 10
}
function Get-SystemDrive {
return $env:SystemDrive[0]
}
function Get-DataDrive {
$driveLetter = Get-SystemDrive
if ((Test-Path env:\BoxStarter:DataDrive) -and (Test-Path $env:BoxStarter:DataDrive)) {
$driveLetter = $env:BoxStarter:DataDrive
}
return $driveLetter
}
function Install-WindowsUpdate {
if (Test-Path env:\BoxStarter:SkipWindowsUpdate) {
return
}
Enable-MicrosoftUpdate
Install-WindowsUpdate -AcceptEula
#if (Test-PendingReboot) { Invoke-Reboot }
}
function Install-WebPackage {
param(
$packageName,
[ValidateSet('exe', 'msi')]
$fileType,
$installParameters,
$downloadFolder,
$url,
$filename
)
if ([String]::IsNullOrEmpty($filename)) {
$filename = Split-Path $url -Leaf
}
$fullFilename = Join-Path $downloadFolder $filename
if (test-path $fullFilename) {
Write-BoxstarterMessage "$fullFilename already exists"
return
}
Get-ChocolateyWebFile $packageName $fullFilename $url
Install-ChocolateyInstallPackage $packageName $fileType $installParameters $fullFilename
}
function Install-WebPackageWithCheckpoint {
param(
$packageName,
[ValidateSet('exe', 'msi')]
$fileType,
$installParameters,
$downloadFolder,
$url,
$filename
)
Use-Checkpoint `
-Function ${Function:Install-WebPackage} `
-CheckpointName $packageName `
-SkipMessage "$packageName is already installed" `
$packageName `
$fileType `
$installParameters `
$downloadFolder `
$url `
$filename
}
function Install-CoreApps {
choco install adobereader --limitoutput
choco install googlechrome --limitoutput
choco install notepadplusplus --limitoutput
choco install 7zip --limitoutput
choco install lastpass --limitoutput --ignorechecksum
choco install filezilla --limitoutput
choco install ditto --limitoutput
choco install microsoft-teams --limitoutput
choco install greenshot --limitoutput
choco install slack --limitoutput
choco install bluejeansapp --limitoutput
}
function Set-ChocoAppPins {
# pin apps that update themselves
choco pin add -n=googlechrome
}
function Install-SqlTools {
param (
$DownloadFolder
)
choco install sql-server-management-studio --limitoutput
}
function Install-CoreDevApps {
choco install dotnetcore-sdk --limitoutput
choco install nuget.commandline --limitoutput
choco install nugetpackageexplorer --limitoutput
choco install fiddler --install-arguments "/D=C:\Program Files\Telerik\Fiddler" --limitoutput
choco install postman --limitoutput
choco install filezilla --limitoutput
choco install dotpeek --limitoutput
choco install soapui --limitoutput
choco install vsts-cli --limitoutput
choco install beyondcompare --limitoutput
}
function Install-VisualStudio2017 {
# install visual studio 2017 community and extensions
choco install visualstudio2017community --limitoutput
choco install visualstudio2017-workload-netcoretools --limitoutput
choco install visualstudio2017-workload-manageddesktop --limitoutput
choco install visualstudio2017-workload-netweb --limitoutput
choco install visualstudio2017-workload-visualstudioextension --limitoutput
choco install visualstudio2017-workload-azure --limitoutput
#install ssdt
choco install ssdt17
}
function Install-InternetInformationServices {
# Enable Internet Information Services Feature - will enable a bunch of things by default
choco install IIS-WebServerRole --source windowsfeatures --limitoutput
# Web Management Tools Features
choco install IIS-ManagementScriptingTools --source windowsfeatures --limitoutput
choco install IIS-IIS6ManagementCompatibility --source windowsfeatures --limitoutput # installs IIS Metbase
# Common Http Features
choco install IIS-HttpRedirect --source windowsfeatures --limitoutput
# .NET Framework 4.5/4.6 Advance Services
choco install NetFx4Extended-ASPNET45 --source windowsfeatures --limitoutput # installs ASP.NET 4.5/4.6
# Application Development Features
choco install IIS-NetFxExtensibility45 --source windowsfeatures --limitoutput # installs .NET Extensibility 4.5/4.6
choco install IIS-ISAPIFilter --source windowsfeatures --limitoutput # required by IIS-ASPNET45
choco install IIS-ISAPIExtensions --source windowsfeatures --limitoutput # required by IIS-ASPNET45
choco install IIS-ASPNET45 --source windowsfeatures --limitoutput # installs support for ASP.NET 4.5/4.6
choco install IIS-ApplicationInit --source windowsfeatures --limitoutput
# Health And Diagnostics Features
choco install IIS-LoggingLibraries --source windowsfeatures --limitoutput # installs Logging Tools
choco install IIS-RequestMonitor --source windowsfeatures --limitoutput
choco install IIS-HttpTracing --source windowsfeatures --limitoutput
choco install IIS-CustomLogging --source windowsfeatures --limitoutput
# Performance Features
choco install IIS-HttpCompressionDynamic --source windowsfeatures --limitoutput
# Security Features
choco install IIS-BasicAuthentication --source windowsfeatures --limitoutput
choco install IIS-WindowsAuthentication --source windowsfeatures --limitoutput
}
function Set-RegionalSettings {
#http://stackoverflow.com/questions/4235243/how-to-set-timezone-using-powershell
&"$env:windir\system32\tzutil.exe" /s "Central Standard Time"
}
function Set-BaseSettings {
Update-ExecutionPolicy -Policy Unrestricted
$sytemDrive = Get-SystemDrive
Set-Volume -DriveLetter $sytemDrive -NewFileSystemLabel "OS"
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -DisableShowProtectedOSFiles -EnableShowFileExtensions -EnableShowFullPathInTitleBar
Set-TaskbarOptions -Combine Never
Enable-RemoteDesktop
Disable-UAC
Disable-InternetExplorerESC
# replace command prompt with powershell in start menu and win+x
Set-CornerNavigationOptions -EnableUsePowerShellOnWinX
}
function Set-UserSettings {
choco install taskbar-never-combine --limitoutput
choco install explorer-show-all-folders --limitoutput
choco install explorer-expand-to-current-folder --limitoutput
}
function Set-BaseDesktopSettings {
if (Test-IsOSWindows10) {
return
}
Install-ChocolateyPinnedTaskBarItem "$($Boxstarter.programFiles86)\Google\Chrome\Application\chrome.exe"
}
function Set-DevDesktopSettings {
if (Test-IsOSWindows10) {
return
}
Install-ChocolateyPinnedTaskBarItem "$($Boxstarter.programFiles86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe"
}
function Move-WindowsLibrary {
param(
$libraryName,
$newPath
)
if (-not (Test-Path $newPath)) {
Move-LibraryDirectory -libraryName $libraryName -newPath $newPath
}
}
function New-SourceCodeFolder {
param(
[string]
$FolderName
)
$sourceCodeFolder = $FolderName
if (Test-Path env:\BoxStarter:SourceCodeFolder) {
$sourceCodeFolder = $env:BoxStarter:SourceCodeFolder
}
if ([System.IO.Path]::IsPathRooted($sourceCodeFolder)) {
$sourceCodePath = $sourceCodeFolder
}
else {
$drivePath = Get-DataDrive
$sourceCodePath = Join-Path "$drivePath`:" $sourceCodeFolder
}
if (-not (Test-Path $sourceCodePath)) {
New-Item $sourceCodePath -ItemType Directory
}
}
function New-InstallCache {
param
(
[String]
$InstallDrive
)
$tempInstallFolder = Join-Path $InstallDrive "temp\install-cache"
if (-not (Test-Path $tempInstallFolder)) {
New-Item $tempInstallFolder -ItemType Directory
}
return $tempInstallFolder
}
function Enable-ChocolateyFeatures {
choco feature enable --name=allowGlobalConfirmation
}
function Disable-ChocolateyFeatures {
choco feature disable --name=allowGlobalConfirmation
}
function Update-Path {
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
}
$dataDriveLetter = Get-DataDrive
$dataDrive = "$dataDriveLetter`:"
$tempInstallFolder = New-InstallCache -InstallDrive $dataDrive
Use-Checkpoint -Function ${Function:Set-RegionalSettings} -CheckpointName 'RegionalSettings' -SkipMessage 'Regional settings are already configured'
# disable chocolatey default confirmation behaviour (no need for --yes)
Use-Checkpoint -Function ${Function:Enable-ChocolateyFeatures} -CheckpointName 'IntializeChocolatey' -SkipMessage 'Chocolatey features already configured'
Use-Checkpoint -Function ${Function:Set-BaseSettings} -CheckpointName 'BaseSettings' -SkipMessage 'Base settings are already configured'
Use-Checkpoint -Function ${Function:Set-UserSettings} -CheckpointName 'UserSettings' -SkipMessage 'User settings are already configured'
Write-BoxstarterMessage "Starting installs"
Use-Checkpoint -Function ${Function:Install-CoreApps} -CheckpointName 'InstallCoreApps' -SkipMessage 'Core apps are already installed'
Use-Checkpoint -Function ${Function:Set-BaseDesktopSettings} -CheckpointName 'BaseDesktopSettings' -SkipMessage 'Base desktop settings are already configured'
Write-BoxstarterMessage "Installing dev apps"
#enable dev related windows features
#setup iis
Use-Checkpoint -Function ${Function:Install-InternetInformationServices} -CheckpointName 'InternetInformationServices' -SkipMessage 'IIS features are already configured'
#install sql tools
Use-Checkpoint -Function ${Function:Install-SqlTools} -CheckpointName 'SqlTools' -SkipMessage 'SQL Tools are already installed'
if (Test-PendingReboot) { Invoke-Reboot }
#install vs2017
Use-Checkpoint -Function ${Function:Install-VisualStudio2017} -CheckpointName 'VisualStudio2017' -SkipMessage 'Visual Studio 2017 is already installed'
#install core apps needed for dev
Use-Checkpoint -Function ${Function:Install-CoreDevApps} -CheckpointName 'CoreDevApps' -SkipMessage 'Core dev apps are already installed'
# make folder for source code
New-SourceCodeFolder -FolderName "VSO"
New-SourceCodeFolder -FolderName "Git"
# pin chocolatey app that self-update
Use-Checkpoint -Function ${Function:Set-ChocoAppPins} -CheckpointName 'ChocoAppPins' -SkipMessage 'Apps are already pinned'
Use-Checkpoint -Function ${Function:Set-DevDesktopSettings} -CheckpointName 'DevDesktopSettings' -SkipMessage 'Dev desktop settings are already configured'
# install chocolatey as last choco package
choco install chocolatey --limitoutput
# re-enable chocolatey default confirmation behaviour
Use-Checkpoint -Function ${Function:Disable-ChocolateyFeatures} -CheckpointName 'DisableChocolatey' -SkipMessage 'Chocolatey features already configured'
if (Test-PendingReboot) { Invoke-Reboot }
# reload path environment variable
Update-Path
Clear-Checkpoints