-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.ps1
206 lines (174 loc) · 8.85 KB
/
script.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
<#
.SYNOPSIS
This PowerShell script configures the Windows environment by removing unnecessary bloatware, installing required tools, and more.
.DESCRIPTION
"WinConfigWizard" is a PowerShell script for automating and optimizing new Windows installations, providing customization, security, and performance enhancements.
.EXAMPLE
PS> ./script.ps1
.LINK
https://github.com/Armoghans-Organization/WinConfigWizard
.NOTES
File Name : script.ps1
Author : Armoghan-ul-Mohmin
Copyright 2024 - Armoghan-ul-Mohmin
#>
# Check if the script is running with Administrator privileges; if not, restart with elevated privileges
if (-not ([System.Security.Principal.WindowsPrincipal][System.Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) {
# Restart script with elevated privileges
Start-Process powershell.exe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
}
##########################################################################
# Functions
##########################################################################
function Write-Banner {
# Define the hardcoded ASCII art banner
$hardcodedBanner = @"
====================================================================================================================
= ==== ==== ================ ================ =============== ==== ==== ============================ =
= ==== ==== =============== === ============== == ============== ==== ==== ============================ =
= ==== ==== ============== ==================== ================== ==== ==== ============================ =
= ==== ==== = = = ====== ======== == = == ==== == ====== ==== ==== = = == == = ===== =
= == == ===== ===== ======= = == ======== = ===== == == ========= = = = = == =
== == == == = = ===== ======= = = = == ===== == ====== == == == ==== ===== = ====== = =
== == == == = = ===== ======= = = = == ===== ==== ====== == == == === ==== = ====== = =
=== == === = = ====== === = = = = == ===== = = ======= == === == ==== = = ====== = =
==== ==== ==== = = ======= === == = == ===== == ========= ==== ==== = == = ======= =
====================================================================================================================
"@
$BannerInfo = @"
Welcome WinConfigWizard - My Windows Setup Script.
Author: Armoghan-ul-Mohmin
Version: 1.0.0
Url: https://github.com/Armoghans-Organization/WinConfigWizard
"@
# Print the colored ASCII art banner to the console
Write-Host $hardcodedBanner -ForegroundColor Red
Write-Host " -----------------------------------------------------------------------------"
Write-Host $BannerInfo -ForegroundColor Blue
Write-Host " -----------------------------------------------------------------------------"
Write-Host
}
function Install-Chocolatey {
# Check if Chocolatey is installed
$chocoInstalled = Get-Command choco -ErrorAction SilentlyContinue
if ($chocoInstalled.ExitCode -eq 0) {
# Chocolatey is not installed; download and install
Write-Host -ForegroundColor Yellow "Chocolatey is not installed. Installing Chocolatey..."
# Define the temporary folder path
$tempFolder = [System.IO.Path]::GetTempPath()
$installerPath = Join-Path -Path $tempFolder -ChildPath "ChocolateyInstall.ps1"
# Download Chocolatey installer to the temporary folder
Invoke-WebRequest -Uri "https://chocolatey.org/install.ps1" -OutFile $installerPath
# Install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression "& '$installerPath'"
# Check if Chocolatey installation was successful
$chocoInstalled = Get-Command choco -ErrorAction SilentlyContinue
if ($chocoInstalled.ExitCode -eq 0) {
Write-Host -ForegroundColor Red "Failed to install Chocolatey."
}
else {
Write-Host -ForegroundColor Green "Chocolatey has been successfully installed."
}
# Remove the installer file after installation
Remove-Item $installerPath -ErrorAction SilentlyContinue
}
else {
# Chocolatey is already installed
Write-Host -ForegroundColor Green "Chocolatey is already installed."
}
}
function Install-Winget {
if (Test-Path ~\AppData\Local\Microsoft\WindowsApps\winget.exe) {
#Checks if winget executable exists and if the Windows Version is 1809 or higher
Write-Host "Winget is Already Installed." -ForegroundColor Green
}
else {
#Gets the computer's information
$ComputerInfo = Get-ComputerInfo
#Gets the Windows Edition
$OSName = if ($ComputerInfo.OSName) {
$ComputerInfo.OSName
}
else {
$ComputerInfo.WindowsProductName
}
if (((($OSName.IndexOf("LTSC")) -ne -1) -or ($OSName.IndexOf("Server") -ne -1)) -and (($ComputerInfo.WindowsVersion) -ge "1809")) {
Write-Host "Running Alternative Installer for LTSC/Server Editions" -ForegroundColor Yellow
# Switching to winget-install from PSGallery from asheroto
# Source: https://github.com/asheroto/winget-in...
Start-Process powershell.exe -Verb RunAs -ArgumentList "-command irm https://raw.githubusercontent.com/ChrisTitusTech/winutil/$BranchToUse/winget.ps1 | iex | Out-Host" -WindowStyle Normal
}
elseif (((Get-ComputerInfo).WindowsVersion) -lt "1809") {
#Checks if Windows Version is too old for winget
Write-Host "Winget is not supported on this version of Windows (Pre-1809)" -ForegroundColor Red
}
else {
#Installing Winget from the Microsoft Store
Write-Host "Winget is not installed. Installing Chocolatey" -ForegroundColor Yellow
Start-Process "ms-appinstaller:?source=https://aka.ms/getwinget"
$nid = (Get-Process AppInstaller).Id
Wait-Process -Id $nid
Write-Host "Winget has been successfully installed." -ForegroundColor Green
}
}
}
function Install-WindowsTerminal {
# Check if Windows Terminal is already installed
$terminalInstalled = Get-Command wt.exe -ErrorAction SilentlyContinue
if ($terminalInstalled.ExitCode -eq 0) {
$chocoResult = choco install microsoft-windows-terminal --force -y
if ($chocoResult.ExitCode -eq 0) {
Write-Host -ForegroundColor Green "Windows Terminal has been successfully installed using Chocolatey."
return
}
else {
Write-Host -ForegroundColor Red "Failed to install Windows Terminal using Chocolatey. Attempting to install using Winget..."
}
# Attempt to install Windows Terminal using Winget
$wingetInstalled = Get-Command winget -ErrorAction SilentlyContinue
if ($wingetInstalled -ne $null) {
Write-Host -ForegroundColor Yellow "Installing Windows Terminal using Winget..."
$wingetResult = winget install Microsoft.WindowsTerminal -e
if ($wingetResult.ExitCode -eq 0) {
Write-Host -ForegroundColor Green "Windows Terminal has been successfully installed using Winget."
return
}
else {
Write-Host -ForegroundColor Red "Failed to install Windows Terminal using Winget."
}
}
else {
Write-Host -ForegroundColor Red "Winget is not available. Cannot install Windows Terminal."
}
}
else {
Write-Host -ForegroundColor Green "Windows Terminal is already installed."
}
}
##########################################################################
# Main script logic
##########################################################################
Clear-Host
# Call the function to print the ASCII art banner
Write-Banner
# Pause for 2 seconds
Start-Sleep -Seconds 2
# Call the function to check and install Chocolatey if necessary
Install-Chocolatey
# Add a line break for readability
Write-Host
# Pause for 2 seconds
Start-Sleep -Seconds 2
# Call the function to check and install Winget if necessary
Install-Winget
# Add a line break for readability
Write-Host
# Pause for 2 seconds
Start-Sleep -Seconds 2
# Call the function to check and install Windows Terminal
Install-WindowsTerminal
# Add a line break for readability
Write-Host
# Pause for 2 seconds
Start-Sleep -Seconds 2