forked from tathamoddie/New-Machine.ps1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
New-Machine.ps1
229 lines (200 loc) · 8.62 KB
/
New-Machine.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
[CmdletBinding()]
param ()
$timer = [System.Diagnostics.Stopwatch]::StartNew()
$ErrorActionPreference = "Stop"
$IsAdmin = (New-Object System.Security.Principal.WindowsPrincipal([System.Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $IsAdmin) {
throw "You need to run this from an elevated pwsh prompt"
}
Write-Host "Setting execution policy" -ForegroundColor Magenta
Set-ExecutionPolicy RemoteSigned
Write-Host "Ensuring PS profile exists" -ForegroundColor Magenta
if (-not (Test-Path $profile)) {
New-Item $profile -Force
}
Write-Progress -Activity "Installing chocolatey"
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString("https://chocolatey.org/install.ps1"))
Write-Host "Reloading powershell profile" -ForegroundColor Magenta
. $profile
Write-Progress -Activity "Installing chocolatey packages"
$chocoPackages = @(
"brave"
"firefox"
"googlechrome"
"microsoft-edge-insider-dev"
"7zip"
"bleachbit"
"vscode"
"notepadplusplus"
"paint.net"
"screentogif"
"sublimetext3"
"baretail"
"docker-desktop"
"fiddler"
"git"
"github-desktop"
"linqpad6"
"microsoft-windows-terminal"
"microsoftazurestorageexplorer"
"nvm.portable"
"postman"
"powershell-core"
"smtp4dev"
"sysinternals"
"signal"
"yarn"
"rescuetime"
)
foreach ($package in $chocoPackages) {
Write-Host "Installing choco package: $package" -ForegroundColor Magenta
choco install -y $package
refreshenv
}
Write-Host "Installing nuget package provider" -ForegroundColor Magenta
Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.208 -Force
Write-Host "Ensuring PowerShell Gallery is trusted" -ForegroundColor Magenta
if (-not ((Get-PackageSource -Name "PSGallery").IsTrusted)) {
$null = Set-PackageSource -Name "PSGallery" -Trusted
}
Write-Host "Installing Powershell modules" -ForegroundColor Magenta
$ModulesToInstall = @(
"Posh-Docker"
"Posh-Git"
"oh-my-posh"
"PSReadLine"
"PSScriptAnalyzer"
)
foreach ($Module in $ModulesToInstall) {
if ($null -eq (Get-Module -Name $Module -ListAvailable)) {
Write-Host ("Installing PowerShell Module - {0}" -f $Module) -ForegroundColor Magenta
$null = Install-Module -Name $Module -Force
}
else {
$InstalledVersion = (Get-Module -Name $Module -ListAvailable)[0].version
$LatestVersion = (Find-Module -Name $Module)[0].version
if ($InstalledVersion -lt $LatestVersion) {
if ($null -eq (Get-Package -Name $Module -ErrorAction SilentlyContinue)) {
Write-Host ("Force Installing PowerShell Module - {0}" -f $Module) -ForegroundColor Magenta
$null = Install-Module -Name $Module -Force
}
else {
Write-Host ("Updating PowerShell Module - {0}" -f $Module) -ForegroundColor Magenta
$null = Update-Module -Name $Module -Force
}
}
}
}
Write-Host "Setting git aliases" -ForegroundColor Magenta
git config --global alias.co "checkout"
git config --global alias.cob "checkout -b"
git config --global alias.df "diff"
git config --global alias.ec "config --global -e"
git config --global alias.f "fetch origin --prune"
git config --global alias.l "log -n 30 --oneline"
git config --global alias.lga "log --graph --oneline --all --decorate"
git config --global alias.st "status"
Write-Host "Setting git credential manager" -ForegroundColor Magenta
git config --global credential.useHttpPath true
git config --global credential.helper wincred #https://code.visualstudio.com/docs/remote/troubleshooting#_sharing-git-credentials-between-windows-and-wsl
Write-Host "Setting VS Code as the Git editor" -ForegroundColor Magenta
git config --global core.editor "code --wait"
# https://cscheng.info/2017/01/26/git-tip-autostash-with-git-pull-rebase.html
Write-Host "Setting autostash with git pull --rebase" -ForegroundColor Magenta
git config --global pull.rebase true
git config --global rebase.autoStash true
$repos = "c:\repos"
Write-Host "Creating $repos folder" -ForegroundColor Magenta
if (-not (Test-Path $repos)) {
New-Item $repos -ItemType Directory
}
$temp = "c:\temp"
Write-Host "Creating $temp folder" -ForegroundColor Magenta
if (-not (Test-Path $temp)) {
New-Item $temp -ItemType Directory
}
Write-Host "Disable Sleep on AC Power..." -ForegroundColor Magenta
Powercfg /Change monitor-timeout-ac 20
Powercfg /Change standby-timeout-ac 0
Write-Host "Removing pre loaded windows 10 apps" -ForegroundColor Magenta
$unWantedApps = @(
"4DF9E0F8.Netflix",
"Fitbit.FitbitCoach",
"king.com.CandyCrushFriends",
"king.com.CandyCrushSaga",
"king.com.FarmHeroesSaga",
"Microsoft.BingNews",
"Microsoft.MicrosoftOfficeHub",
"Microsoft.MicrosoftSolitaireCollection"
"Microsoft.MicrosoftSolitaireCollection",
"Microsoft.MicrosoftStickyNotes",
"Microsoft.Office.OneNote",
"Microsoft.SkypeApp",
"Microsoft.ZuneMusic"
)
foreach ($app in $unWantedApps) {
Write-Host "Removing $app" -ForegroundColor Magenta
Get-AppxPackage -Name $app | Remove-AppxPackage
}
Write-Host "Setting windows explorer options" -ForegroundColor Magenta
$key = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer"
$advancedKey = "$key\Advanced"
$cabinetStateKey = "$key\CabinetState"
if (Test-Path -Path $key) {
Write-Host "EnableShowRecentFilesInQuickAccess" -ForegroundColor Magenta
Set-ItemProperty $key ShowRecent 1
Write-Host "EnableShowFrequentFoldersInQuickAccess" -ForegroundColor Magenta
Set-ItemProperty $key ShowFrequent 1
}
if (Test-Path -Path $advancedKey) {
Write-Host "EnableShowHiddenFilesFoldersDrives" -ForegroundColor Magenta
Set-ItemProperty $advancedKey Hidden 1
Write-Host "EnableShowFileExtensions" -ForegroundColor Magenta
Set-ItemProperty $advancedKey HideFileExt 0
Write-Host "EnableShowProtectedOSFiles" -ForegroundColor Magenta
Set-ItemProperty $advancedKey ShowSuperHidden 1
Write-Host "EnableExpandToOpenFolder" -ForegroundColor Magenta
Set-ItemProperty $advancedKey NavPaneExpandToCurrentFolder 1
Write-Host "EnableOpenFileExplorerToQuickAccess" -ForegroundColor Magenta
Set-ItemProperty $advancedKey LaunchTo 2
}
if (Test-Path -Path $cabinetStateKey) {
Write-Host "EnableShowFullPathInTitleBar" -ForegroundColor Magenta
Set-ItemProperty $cabinetStateKey FullPath 1
}
Write-Host "Enabling windows features" -ForegroundColor Magenta
$features = @(
"Microsoft-Hyper-V-All"
"Containers"
"VirtualMachinePlatform"
"HypervisorPlatform"
"Microsoft-Windows-Subsystem-Linux"
)
foreach ($feature in $features) {
Write-Host "Enabling windows feature: $feature" -ForegroundColor Magenta
Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName $feature
}
Write-Host "Reloading powershell profile" -ForegroundColor Magenta
. $profile
# disable progress report as Invoke-WebRequest is playing up
$ProgressPreference = 'SilentlyContinue'
# https://docs.microsoft.com/en-us/windows/wsl/install-manual
Write-Host "Downloading ubuntu distro."
$ubuntu = ".\Ubuntu.appx"
Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile $ubuntu -UseBasicParsing; Write-Host "Installing ubuntu distro."; Add-AppxPackage $ubuntu; Remove-Item $ubuntu; Write-Host "Finished installing ubuntu distro."
Write-Host "Downloading kali distro."
$kali = ".\Kali.appx"
Invoke-WebRequest -Uri https://aka.ms/wsl-kali-linux-new -OutFile $kali -UseBasicParsing; Write-Host "Installing kali distro."; Add-AppxPackage $kali; Remove-Item $kali; Write-Host "Finished installing kali distro."
Write-Host "Downloading azure cli."
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Write-Host "Installing azure cli."; Start-Process msiexec.exe -Wait -ArgumentList "/I AzureCLI.msi /quiet"; Remove-Item .\AzureCLI.msi; Write-Host "Finished installing azure cli."
$timer.Stop()
Write-Host ""
Write-Host "Script run for $($timer.Elapsed.ToString("hh\:mm\:ss")), it could have taken you at least 3x amount of time if you have to do it manually." -ForegroundColor Green
Write-Host "Now do the following:" -ForegroundColor Yellow
Write-Host "1. Reboot." -ForegroundColor Yellow
Write-Host "2. Do a windows update." -ForegroundColor Yellow
Write-Host "3. Finalized the installation of WSL distros by running them." -ForegroundColor Yellow
Write-Host "4. Enjoy your new machine. :)" -ForegroundColor Yellow
Write-Host ""
Read-Host -Prompt "All done, press [ENTER] to restart your computer '$env:COMPUTERNAME'"
Restart-Computer