-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup.ps1
More file actions
390 lines (328 loc) · 14.3 KB
/
Setup.ps1
File metadata and controls
390 lines (328 loc) · 14.3 KB
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
<#
.SYNOPSIS
PowerShell 7 Environment Setup Script - Automated configuration and module installation
.DESCRIPTION
This script automates the setup process for a complete PowerShell 7 development environment.
It performs system checks, installs required modules, configures repositories, and prepares
the environment for enhanced PowerShell usage with modern tools and utilities.
The script handles:
- Administrator privilege verification
- Internet connectivity testing
- Git installation verification
- SSH for Windows feature installation
- Chocolatey package manager verification
- PowerShellGet module configuration
- PSGallery repository trust configuration
- Essential PowerShell modules installation
- Comprehensive error handling and reporting
.PARAMETER Verbose
Enables verbose output for detailed logging of operations
.PARAMETER WhatIf
Shows what would be performed without actually executing the operations
.EXAMPLE
.\Setup.ps1
Runs the setup script with default parameters, installing all required modules
and configuring the PowerShell environment.
.EXAMPLE
.\Setup.ps1 -Verbose
Runs the setup script with verbose output, providing detailed information
about each operation performed.
.EXAMPLE
.\Setup.ps1 -WhatIf
Shows what operations would be performed without actually executing them.
Useful for testing and verification.
Get-Help .\Setup.ps1
Provides necessary documentation
.INPUTS
None. This script does not accept pipeline input.
.OUTPUTS
Console output with colored status messages, progress indicators, and summary report.
.NOTES
File Name : Setup.ps1
Author : Abdul Hakim (alarwasyi98)
Prerequisite : PowerShell 7.0 or higher
Created : 2025-06-14
Last Modified : 2025-06-14
Version : 1.0.0
Requirements:
- PowerShell 7.0 or higher
- Internet connection for module downloads
- Windows 10/11 or Windows Server 2019/2022
- Administrator privileges (recommended for full functionality)
Modules Installed:
- Terminal-Icons : Provides file and folder icons in terminal
- PSReadLine : Enhanced command line editing experience
- Microsoft.WinGet.CommandNotFound : Command suggestions for missing commands
- ps-color-scripts : Colorful terminal scripts and themes
- PSFzf : Fuzzy finder integration for PowerShell
- PSWebSearch : Web search capabilities from PowerShell
Security:
- All modules are installed from trusted PSGallery repository
- Script includes comprehensive error handling
- No external executables are downloaded or executed
- All operations are logged with colored output
.LINK
https://github.com/alarwasyi98/PowerShell
https://docs.microsoft.com/en-us/powershell/
https://www.powershellgallery.com/
.COMPONENT
PowerShell Environment Setup
.ROLE
System Configuration
.FUNCTIONALITY
Automated PowerShell environment setup and module installation
.USAGE
1. Download the Setup.ps1 script to your desired location
2. Open PowerShell 7 as Administrator (recommended)
3. Navigate to the script directory
4. Set execution policy if needed: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
5. Run the script: .\Setup.ps1
6. Follow the on-screen instructions and status messages
7. Restart PowerShell session after completion
8. Copy your PowerShell profile configuration to $PROFILE location
Post-Setup Recommendations:
- Install additional tools via winget (Oh My Posh, fzf, zoxide, bat, neovim, yazi)
- Configure your PowerShell profile with custom functions and aliases
- Set up Starship prompt configuration
- Configure SSH keys and Git credentials
#>
#Requires -Version 7.0
[CmdletBinding()]
param()
# .__
# _____ | | POWERSHELL 7 SETUP SCRIPT
# \__ \ | | Abdul Hakim (alarwasyi98)
# / __ \| |__ https://github.com/alarwasyi98/PowerShell
# (____ /____/ Version 1.0.0
# \/
# Script metadata
$ScriptInfo = @{
Name = "PowerShell 7 Environment Setup Script"
Version = "1.0.0"
Author = "Abdul Hakim (alarwasyi98)"
Created = "2025-06-14"
Repository = "https://github.com/alarwasyi98/PowerShell"
Description = "Automated PowerShell 7 environment configuration and module installation"
}
# Color definitions for output
$Red = [System.ConsoleColor]::Red
$Green = [System.ConsoleColor]::Green
$Yellow = [System.ConsoleColor]::Yellow
$Cyan = [System.ConsoleColor]::Cyan
$White = [System.ConsoleColor]::White
$Magenta = [System.ConsoleColor]::Magenta
function Write-ColorOutput {
param(
[string]$Message,
[System.ConsoleColor]$Color = $White
)
Write-Host $Message -ForegroundColor $Color
}
function Write-Step {
param([string]$Message)
Write-ColorOutput "`n[STEP] $Message" $Cyan
}
function Write-Success {
param([string]$Message)
Write-ColorOutput "[SUCCESS] $Message" $Green
}
function Write-Warning {
param([string]$Message)
Write-ColorOutput "[WARNING] $Message" $Yellow
}
function Write-Error {
param([string]$Message)
Write-ColorOutput "[ERROR] $Message" $Red
}
function Test-Administrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Test-InternetConnection {
try {
$testConnection = Test-NetConnection -ComputerName "8.8.8.8" -Port 53 -InformationLevel Quiet -WarningAction SilentlyContinue
return $testConnection
}
catch {
return $false
}
}
function Install-ModuleWithErrorHandling {
param(
[string]$ModuleName,
[switch]$AllowPrerelease
)
try {
Write-Step "Installing $ModuleName module..."
if (Get-Module -ListAvailable -Name $ModuleName) {
Write-Warning "$ModuleName is already installed. Updating..."
if ($AllowPrerelease) {
Update-Module -Name $ModuleName -AllowPrerelease -Force -ErrorAction Stop
} else {
Update-Module -Name $ModuleName -Force -ErrorAction Stop
}
} else {
if ($AllowPrerelease) {
Install-Module -Name $ModuleName -AllowPrerelease -Scope CurrentUser -Force -ErrorAction Stop
} else {
Install-Module -Name $ModuleName -Scope CurrentUser -Force -ErrorAction Stop
}
}
Write-Success "$ModuleName installed/updated successfully"
return $true
}
catch {
Write-Error "Failed to install $ModuleName : $($_.Exception.Message)"
return $false
}
}
# Main Setup Function
function Start-PowerShellSetup {
Write-ColorOutput @"
╔══════════════════════════════════════════════════════════════╗
║ PowerShell 7 Setup Script ║
║ Abdul Hakim (alarwasyi98) ║
║ https://github.com/alarwasyi98/PowerShell ║
╚══════════════════════════════════════════════════════════════╝
"@ $Cyan
# Check Administrator Privileges
Write-Step "Checking administrator privileges..."
if (-not (Test-Administrator)) {
Write-Warning "Some features require administrator privileges."
Write-ColorOutput "Consider running as administrator for full functionality." $Yellow
} else {
Write-Success "Running with administrator privileges"
}
# Check Internet Connection
Write-Step "Checking internet connection..."
if (-not (Test-InternetConnection)) {
Write-Error "No internet connection detected. Cannot proceed with setup."
return
}
Write-Success "Internet connection verified"
# Check Git Installation
Write-Step "Checking Git installation..."
try {
$gitVersion = git --version 2>$null
if ($gitVersion) {
Write-Success "Git is installed: $gitVersion"
} else {
throw "Git not found"
}
}
catch {
Write-Warning "Git is not installed or not in PATH"
Write-ColorOutput "Please install Git from: https://git-scm.com/download/win" $Yellow
Write-ColorOutput "Or use: winget install Git.Git" $Yellow
}
# Check SSH for Windows Feature
Write-Step "Checking SSH for Windows feature..."
try {
$sshClient = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Client*'
$sshServer = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'
if ($sshClient.State -eq "Installed") {
Write-Success "SSH Client is installed"
} else {
Write-Warning "SSH Client is not installed"
if (Test-Administrator) {
try {
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Write-Success "SSH Client installed successfully"
}
catch {
Write-Error "Failed to install SSH Client: $($_.Exception.Message)"
}
} else {
Write-ColorOutput "Run as administrator to install SSH Client automatically" $Yellow
}
}
}
catch {
Write-Error "Failed to check SSH installation: $($_.Exception.Message)"
}
# Check Chocolatey Installation
Write-Step "Checking Chocolatey installation..."
try {
$chocoVersion = choco --version 2>$null
if ($chocoVersion) {
Write-Success "Chocolatey is installed: v$chocoVersion"
} else {
throw "Chocolatey not found"
}
}
catch {
Write-Warning "Chocolatey is not installed"
Write-ColorOutput "Install from: https://chocolatey.org/install" $Yellow
Write-ColorOutput "Or run: Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" $Yellow
}
# Configure PowerShellGet and PSGallery
Write-Step "Configuring PowerShellGet and PSGallery repository..."
try {
# Update PowerShellGet
if (Get-Module -ListAvailable -Name PowerShellGet) {
Write-Success "PowerShellGet is available"
Update-Module PowerShellGet -Force -ErrorAction SilentlyContinue
} else {
Install-Module PowerShellGet -Force -AllowClobber -ErrorAction Stop
}
# Set PSGallery as trusted
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -ErrorAction Stop
Write-Success "PSGallery repository set to trusted"
}
catch {
Write-Error "Failed to configure PowerShellGet/PSGallery: $($_.Exception.Message)"
}
# Install Required Modules
$modules = @(
@{ Name = "Terminal-Icons"; AllowPrerelease = $false },
@{ Name = "PSReadLine"; AllowPrerelease = $true },
@{ Name = "Microsoft.WinGet.CommandNotFound"; AllowPrerelease = $false },
@{ Name = "ps-color-scripts"; AllowPrerelease = $false },
@{ Name = "PSFzf"; AllowPrerelease = $false },
@{ Name = "PSWebSearch"; AllowPrerelease = $false }
)
$successCount = 0
$totalModules = $modules.Count
foreach ($module in $modules) {
if ($module.AllowPrerelease) {
$result = Install-ModuleWithErrorHandling -ModuleName $module.Name -AllowPrerelease
} else {
$result = Install-ModuleWithErrorHandling -ModuleName $module.Name
}
if ($result) {
$successCount++
}
}
# Summary
Write-ColorOutput "`n╔══════════════════════════════════════════════════════════════╗" $Cyan
Write-ColorOutput "║ SETUP SUMMARY ║" $Cyan
Write-ColorOutput "╚════════════════════════════════════════════════════════════════╝" $Cyan
Write-ColorOutput "`nModules Installation: $successCount/$totalModules completed" $White
if ($successCount -eq $totalModules) {
Write-Success "`nAll modules installed successfully!"
} else {
Write-Warning "`nSome modules failed to install. Check the errors above."
}
Write-ColorOutput "`nNext Steps:" $Cyan
Write-ColorOutput "1. Restart your PowerShell session" $White
Write-ColorOutput "2. Copy your PowerShell profile to: $PROFILE" $White
Write-ColorOutput "3. Install additional tools:" $White
Write-ColorOutput " - winget install junegunn.fzf" $White
Write-ColorOutput " - winget install ajeetdsouza.zoxide" $White
Write-ColorOutput " - winget install sharkdp.bat" $White
Write-ColorOutput " - winget install Neovim.Neovim" $White
Write-ColorOutput " - winget install sxyazi.yazi" $White
Write-ColorOutput "`nSetup completed! Enjoy your enhanced PowerShell experience! 🚀" $Green
}
# Execute the setup
try {
Start-PowerShellSetup
}
catch {
Write-Error "Setup failed with error: $($_.Exception.Message)"
Write-ColorOutput "Please check the error details above and try again." $Yellow
}
# Pause to allow user to read the output
Write-Host "`nPress any key to continue..." -ForegroundColor Yellow
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")