forked from mxtaooo/EnvSetup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Install.ps1
326 lines (284 loc) · 15.8 KB
/
Install.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
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
function Check-Command($cmdname) {
return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue)
}
function AddToPath {
param (
[string]$folder
)
Write-Host "Adding $folder to environment variables..." -ForegroundColor Yellow
$currentEnv = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine).Trim(";");
$addedEnv = $currentEnv + ";$folder"
$trimmedEnv = (($addedEnv.Split(';') | Select-Object -Unique) -join ";").Trim(";")
[Environment]::SetEnvironmentVariable(
"Path",
$trimmedEnv,
[EnvironmentVariableTarget]::Machine)
#Write-Host "Reloading environment variables..." -ForegroundColor Green
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
}
function Remove-UWP {
param (
[string]$name
)
Write-Host "Removing UWP $name..." -ForegroundColor Yellow
Get-AppxPackage $name | Remove-AppxPackage
Get-AppxPackage $name | Remove-AppxPackage -AllUsers
}
Write-Host "OS Info:" -ForegroundColor Green
Get-CimInstance Win32_OperatingSystem | Format-List Name, Version, InstallDate, OSArchitecture
(Get-ItemProperty HKLM:\HARDWARE\DESCRIPTION\System\CentralProcessor\0\).ProcessorNameString
# -----------------------------------------------------------------------------
$computerName = Read-Host 'Enter New Computer Name'
Write-Host "Renaming this computer to: " $computerName -ForegroundColor Yellow
Rename-Computer -NewName $computerName
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "Disable Sleep on AC Power..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
Powercfg /Change monitor-timeout-ac 20
Powercfg /Change standby-timeout-ac 0
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "Add 'This PC' Desktop Icon..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
$thisPCIconRegPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel"
$thisPCRegValname = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
$item = Get-ItemProperty -Path $thisPCIconRegPath -Name $thisPCRegValname -ErrorAction SilentlyContinue
if ($item) {
Set-ItemProperty -Path $thisPCIconRegPath -name $thisPCRegValname -Value 0
}
else {
New-ItemProperty -Path $thisPCIconRegPath -Name $thisPCRegValname -Value 0 -PropertyType DWORD | Out-Null
}
# To list all appx packages:
# Get-AppxPackage | Format-Table -Property Name,Version,PackageFullName
Write-Host "Removing UWP Rubbish..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
$uwpRubbishApps = @(
"Microsoft.Microsoft3DViewer"
"Microsoft.ZuneMusic"
"Microsoft.ZuneVideo"
"*549981C3F5F10*"
"Microsoft.WindowsSoundRecorder"
"Microsoft.PowerAutomateDesktop"
"Microsoft.BingWeather"
"Microsoft.BingNews"
"king.com.CandyCrushSaga"
"Microsoft.Messaging"
"Microsoft.WindowsFeedbackHub"
"Microsoft.MicrosoftOfficeHub"
"Microsoft.MicrosoftSolitaireCollection"
"4DF9E0F8.Netflix"
"Microsoft.GetHelp"
"Microsoft.People"
"Microsoft.YourPhone"
"MicrosoftTeams"
"Microsoft.Getstarted"
"Microsoft.Microsoft3DViewer"
"Microsoft.WindowsMaps"
"Microsoft.MixedReality.Portal"
"Microsoft.SkypeApp")
foreach ($uwp in $uwpRubbishApps) {
Remove-UWP $uwp
}
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "Starting UWP apps to upgrade..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
$namespaceName = "root\cimv2\mdm\dmmap"
$className = "MDM_EnterpriseModernAppManagement_AppManagement01"
$wmiObj = Get-WmiObject -Namespace $namespaceName -Class $className
$result = $wmiObj.UpdateScanMethod()
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "Installing IIS..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
Enable-WindowsOptionalFeature -Online -FeatureName IIS-DefaultDocument -All
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionDynamic -All
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionStatic -All
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebSockets -All
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationInit -All
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45 -All
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ServerSideIncludes
Enable-WindowsOptionalFeature -Online -FeatureName IIS-BasicAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WindowsAuthentication
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "Enable Windows 11 Developer Mode..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "Enable Remote Desktop..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\" -Name "fDenyTSConnections" -Value 0
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\" -Name "UserAuthentication" -Value 1
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
if (Check-Command -cmdname 'choco') {
Write-Host "Choco is already installed, skip installation."
}
else {
Write-Host ""
Write-Host "Installing Chocolate for Windows..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}
Write-Host ""
Write-Host "Installing Applications..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
Write-Host "[WARN] Ma de in China: please consider using the true Internet first" -ForegroundColor Yellow
$Apps = @(
"7zip.install",
"git",
"vlc",
"vscode",
"sysinternals",
"linqpad",
"postman",
"beyondcompare",
"microsoft-teams.install",
"github-desktop",
"irfanview",
"nodejs-lts",
"azure-cli",
"powershell-core",
"obs-studio")
foreach ($app in $Apps) {
choco install $app -y
}
Write-Host "Setting up Git for Windows..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
git config --global user.email "edi.wang@outlook.com"
git config --global user.name "Edi Wang"
git config --global core.autocrlf true
#aria2
if ($true)
{
Write-Host "Installing aria2 as download tool..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
$downloadAddress = "https://github.com/aria2/aria2/releases/download/release-1.36.0/aria2-1.36.0-win-64bit-build1.zip"
Invoke-WebRequest $downloadAddress -OutFile "$HOME\aria2.zip"
$installPath = "${env:ProgramFiles}\aria2"
& "${env:ProgramFiles}\7-Zip\7z.exe" x "$HOME\aria2.zip" "-o$($installPath)" -y
$subPath = $(Get-ChildItem -Path $installPath | Where-Object { $_.Name -like "aria2-*" } | Sort-Object Name -Descending | Select-Object -First 1).Name
$subPath = Join-Path -Path $installPath -ChildPath $subPath
Remove-Item $installPath\aria2c.exe -ErrorAction SilentlyContinue
Move-Item $subPath\aria2c.exe $installPath
AddToPath -folder $installPath
Remove-Item -Path "$HOME\aria2.zip" -Force
}
# Android CLI
if ($true) {
Write-Host "Downloading Android-Platform-Tools (To connect to Android Phone)..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
$toolsPath = "${env:ProgramFiles}\Android-Platform-Tools"
$downloadUri = "https://dl.google.com/android/repository/platform-tools-latest-windows.zip"
$downloadedTool = $env:USERPROFILE + "\platform-tools-latest-windows.zip"
Remove-Item $downloadedTool -ErrorAction SilentlyContinue
aria2c.exe $downloadUri -d $HOME -o "platform-tools-latest-windows.zip"
& ${env:ProgramFiles}\7-Zip\7z.exe x $downloadedTool "-o$($toolsPath)" -y
AddToPath -folder "$toolsPath\platform-tools"
Remove-Item -Path $downloadedTool -Force
}
# FFmpeg
if ($true) {
Write-Host "Downloading FFmpeg..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
$ffmpegPath = "${env:ProgramFiles}\FFMPEG"
$downloadUri = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-git-full.7z"
$downloadedFfmpeg = $env:USERPROFILE + "\ffmpeg-git-full.7z"
Remove-Item $downloadedFfmpeg -ErrorAction SilentlyContinue
aria2c.exe $downloadUri -d $HOME -o "ffmpeg-git-full.7z"
& ${env:ProgramFiles}\7-Zip\7z.exe x $downloadedFfmpeg "-o$($ffmpegPath)" -y
$subPath = $(Get-ChildItem -Path $ffmpegPath | Where-Object { $_.Name -like "ffmpeg*" } | Sort-Object Name -Descending | Select-Object -First 1).Name
$subPath = Join-Path -Path $ffmpegPath -ChildPath $subPath
$binPath = Join-Path -Path $subPath -ChildPath "bin"
Remove-Item $ffmpegPath\*.exe
Move-Item $binPath\*.exe $ffmpegPath
Write-Host "Adding FFmpeg to PATH..." -ForegroundColor Green
AddToPath -folder $ffmpegPath
Remove-Item -Path $downloadedFfmpeg -Force
}
# wget
if ($true) {
Write-Host "Downloading Wget because some app may need it..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
$wgetPath = "${env:ProgramFiles}\wget"
$downloadUri = "https://eternallybored.org/misc/wget/releases/wget-1.21.3-win64.zip"
$downloadedWget = $env:USERPROFILE + "\wget-1.21.3-win64.zip"
Remove-Item $downloadedWget -ErrorAction SilentlyContinue
aria2c.exe $downloadUri -d $HOME -o "wget-1.21.3-win64.zip"
& ${env:ProgramFiles}\7-Zip\7z.exe x $downloadedWget "-o$($wgetPath)" -y
Write-Host "Adding wget to PATH..." -ForegroundColor Green
AddToPath -folder $wgetPath
Remove-Item -Path $downloadedWget -Force
}
Write-Host "Setting up dotnet for Windows..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
[Environment]::SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development", "Machine")
[Environment]::SetEnvironmentVariable("DOTNET_PRINT_TELEMETRY_MESSAGE", "false", "Machine")
[Environment]::SetEnvironmentVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1", "Machine")
dotnet tool update --global dotnet-ef
Write-Host "Set home path hidden folders and files..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
Get-ChildItem -Path $HOME -Filter .* -Recurse -Force -ErrorAction SilentlyContinue | ForEach-Object { $_.Attributes = $_.Attributes -bor [System.IO.FileAttributes]::Hidden }
Write-Host "Avoid Edge showing sidebar..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -ErrorAction SilentlyContinue
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Name HubsSidebarEnabled -Type DWORD -Value 0 -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Name HubsSidebarEnabled -Type DWORD -Value 0
Write-Host "Disabling Alt+Tab swiching Edge tabs..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -ErrorAction SilentlyContinue
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name MultiTaskingAltTabFilter -Type DWORD -Value 3 -ErrorAction SilentlyContinue
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name MultiTaskingAltTabFilter -Type DWORD -Value 3
Write-Host "Avoid rubbish folder grouping..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
(gci 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags' -s | ? PSChildName -eq '{885a186e-a440-4ada-812b-db871b942259}' ) | ri -Recurse
Write-Host "Enabling Chinese input method..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
$LanguageList = Get-WinUserLanguageList
$LanguageList.Add("zh-CN")
Set-WinUserLanguageList $LanguageList -Force
Write-Host "Applying file explorer settings..." -ForegroundColor Green
cmd.exe /c "reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v HideFileExt /t REG_DWORD /d 0 /f"
cmd.exe /c "reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v AutoCheckSelect /t REG_DWORD /d 0 /f"
cmd.exe /c "reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v LaunchTo /t REG_DWORD /d 1 /f"
Write-Host "Disabling the Windows Ink Workspace..." -ForegroundColor Green
REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\PenWorkspace" /V PenWorkspaceButtonDesiredVisibility /T REG_DWORD /D 0 /F
Write-Host "Exclude repos from Windows Defender..." -ForegroundColor Green
Add-MpPreference -ExclusionPath "$env:USERPROFILE\source\repos"
Add-MpPreference -ExclusionPath "$env:USERPROFILE\.nuget"
Add-MpPreference -ExclusionPath "$env:USERPROFILE\.vscode"
Add-MpPreference -ExclusionPath "$env:USERPROFILE\.dotnet"
Add-MpPreference -ExclusionPath "$env:USERPROFILE\.ssh"
Add-MpPreference -ExclusionPath "$env:USERPROFILE\.azuredatastudio"
Add-MpPreference -ExclusionPath "$env:APPDATA\npm"
Add-MpPreference -ExclusionPath "$NextcloudPath"
Write-Host "Syncing time..." -ForegroundColor Green
net stop w32time
net start w32time
w32tm /resync /force
w32tm /query /status
Write-Host "Setting Time zone..." -ForegroundColor Green
Set-TimeZone -Name "China Standard Time"
Write-Host "Enabling Hardware-Accelerated GPU Scheduling..." -ForegroundColor Green
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\" -Name 'HwSchMode' -Value '2' -PropertyType DWORD -Force
Write-Host "Installing github.com/microsoft/artifacts-credprovider..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1'))
Write-Host "Removing Bluetooth icons..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
cmd.exe /c "reg add `"HKCU\Control Panel\Bluetooth`" /v `"Notification Area Icon`" /t REG_DWORD /d 0 /f"
# -----------------------------------------------------------------------------
Write-Host ""
Write-Host "Checking Windows updates..." -ForegroundColor Green
Write-Host "------------------------------------" -ForegroundColor Green
Install-Module -Name PSWindowsUpdate -Force
Write-Host "Installing updates... (Computer will reboot in minutes...)" -ForegroundColor Green
Get-WindowsUpdate -AcceptAll -Install -ForceInstall -AutoReboot
# -----------------------------------------------------------------------------
Write-Host "------------------------------------" -ForegroundColor Green
Read-Host -Prompt "Setup is done, restart is needed, press [ENTER] to restart computer."
Restart-Computer