Last active
January 27, 2025 12:33
-
-
Save djonasdev/a8bc9c5c1e6899a7c620be9403b59d8c to your computer and use it in GitHub Desktop.
Setup fresh Windows installation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ensure the script is run as administrator | |
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | |
Write-Host "The script must be run as Administrator. Restarting with elevated privileges..." | |
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs | |
exit | |
} | |
# Define the log file path | |
$LogFile = "$PSScriptRoot\install_log.txt" | |
# Function to log messages | |
function Write-Log { | |
param ( | |
[string]$Message, | |
[string]$Level = "INFO" | |
) | |
$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" | |
"$Timestamp [$Level] $Message" | Tee-Object -FilePath $LogFile -Append | |
} | |
Write-Log "Script started." | |
# Step 1: Run debloat script | |
try { | |
Write-Log "Running debloat script." | |
& ([scriptblock]::Create((irm "https://debloat.raphi.re/"))) -RunDefaults -Silent | |
Write-Log "Debloat script executed successfully." | |
} catch { | |
Write-Log "Failed to execute debloat script: $($_)" -Level "ERROR" | |
} | |
# Step 2: Install Chocolatey | |
try { | |
Write-Log "Installing Chocolatey." | |
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')) | |
Write-Log "Chocolatey installed successfully." | |
} catch { | |
Write-Log "Failed to install Chocolatey: $($_)" -Level "ERROR" | |
} | |
# Step 3: Install software using Chocolatey | |
#foreach ($Package in $Packages) { | |
# try { | |
# Write-Log "Installing package: $Package" | |
# choco install $Package -y | Tee-Object -FilePath $LogFile -Append | |
# Write-Log "Successfully installed $Package." | |
# } catch { | |
# Write-Log "Failed to install ${Package}: $($_)" -Level "ERROR" | |
# } | |
#} | |
$InstallScript = { | |
param ($LogFile) | |
Set-ExecutionPolicy Bypass -Scope Process -Force | |
# Define the list of packages to install internally | |
$Packages = @( | |
"firefox", | |
"7zip", | |
"vscode", | |
"powertoys", | |
"treesizefree", | |
"greenshot", | |
"irfanview", | |
"sentinel", | |
"sqlitebrowser", | |
"tightvnc", | |
"adobereader" | |
) | |
# Chocolatey environment variables | |
$env:ChocolateyInstall = "C:\ProgramData\chocolatey" | |
$env:PATH += ";$env:ChocolateyInstall\bin" | |
# Check if choco is available | |
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) { | |
Write-Host "Chocolatey is not installed or not found in the PATH." | |
exit | |
} | |
# Install packages | |
foreach ($Package in $Packages) { | |
try { | |
Write-Host "Installing package: $Package" | |
choco install $Package -y | Tee-Object -FilePath $LogFile -Append | |
Write-Host "Successfully installed $Package." | |
} catch { | |
Write-Host "Failed to install ${Package}: $($_)" -Level "ERROR" | |
} | |
} | |
} | |
# Starte PowerShell mit Administratorrechten und führe das Skript aus | |
$ScriptPath = "$PSScriptRoot\install_software.ps1" | |
# Erstelle eine temporäre Datei mit dem Installationscode | |
$InstallScript | Out-File -FilePath $ScriptPath -Encoding UTF8 | |
# Starte die neue PowerShell-Instanz mit Administratorrechten und führe das Installationsskript aus | |
Start-Process powershell -Verb runAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$ScriptPath`" $Packages $LogFile" | |
Write-Log "Script completed." |
Author
djonasdev
commented
Jan 27, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment