Skip to content

Instantly share code, notes, and snippets.

@djonasdev
Last active January 27, 2025 12:33
Show Gist options
  • Save djonasdev/a8bc9c5c1e6899a7c620be9403b59d8c to your computer and use it in GitHub Desktop.
Save djonasdev/a8bc9c5c1e6899a7c620be9403b59d8c to your computer and use it in GitHub Desktop.
Setup fresh Windows installation
# 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."
@djonasdev
Copy link
Author

& ([scriptblock]::Create((irm "https://gist.githubusercontent.com/djonasdev/a8bc9c5c1e6899a7c620be9403b59d8c/raw")))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment