109 lines
3.2 KiB
PowerShell
109 lines
3.2 KiB
PowerShell
# Elevate privileges if needed
|
|
if (-not ([Security.Principal.WindowsPrincipal]::new([Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
|
[Security.Principal.WindowsBuiltInRole]::Administrator))) {
|
|
Start-Process powershell -Verb runAs -ArgumentList $MyInvocation.MyCommand.Definition
|
|
exit
|
|
}
|
|
|
|
function Show-Banner {
|
|
Clear-Host
|
|
Write-Host @"
|
|
MAGICIS - SUPPORT A VETERAN
|
|
"@ -ForegroundColor Cyan
|
|
}
|
|
|
|
function Show-Menu {
|
|
Show-Banner
|
|
Write-Host "========== CONFIGURATION MENU ==========" -ForegroundColor Cyan
|
|
Write-Host "1. Rename PC using MAC Address AND RESTART"
|
|
Write-Host "2. Run magicis-install.ps1"
|
|
Write-Host "3. Exit"
|
|
Write-Host "========================================`n"
|
|
}
|
|
|
|
|
|
function Rename-PCToMac() {
|
|
Write-Output "`nRenaming PC using MAC address..."
|
|
$mac = (Get-NetAdapter -InterfaceAlias "*Ethernet*" | Select-Object -First 1 -ExpandProperty MacAddress) -replace '-', ''
|
|
if ($mac) {
|
|
Rename-Computer -NewName "$mac" -Force
|
|
Write-Output "Computer renamed to: $mac"
|
|
Write-Output "Restarting Computer to apply settings in 10 seconds"
|
|
Start-Sleep -Seconds 10
|
|
Restart-Computer -Force
|
|
} else {
|
|
Write-Output "Could not retrieve MAC address.`n"
|
|
}
|
|
}
|
|
|
|
# Log path
|
|
$Global:LogFile = "C:\temp\system_tweaks.log"
|
|
|
|
# Helper function to log messages to console and file
|
|
function Write-Log {
|
|
param(
|
|
[string]$Message,
|
|
[string]$Level = "INFO"
|
|
)
|
|
|
|
$timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
|
|
$line = "[$timestamp] [$Level] $Message"
|
|
|
|
# Console
|
|
Write-Output $line
|
|
|
|
# File
|
|
try {
|
|
$dir = Split-Path $Global:LogFile -Parent
|
|
if (-not (Test-Path $dir)) {
|
|
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
|
}
|
|
Add-Content -Path $Global:LogFile -Value $line
|
|
} catch {
|
|
Write-Output "Error writing log to $Global:LogFile : $_"
|
|
}
|
|
}
|
|
|
|
|
|
function Run-MagicisInstall {
|
|
Write-Log "Starting magicis-install.ps1..."
|
|
try {
|
|
$scriptPath = Join-Path -Path $PSScriptRoot -ChildPath "magicis-install.ps1"
|
|
if (-not (Test-Path $scriptPath)) {
|
|
Write-Log "magicis-install.ps1 not found at $scriptPath. Please place it in the same folder or update the path." "ERROR"
|
|
return
|
|
}
|
|
# Run with bypass to avoid policy issues; current session is already elevated
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File $scriptPath
|
|
Write-Log "magicis-install.ps1 finished."
|
|
} catch {
|
|
Write-Log "Error running magicis-install.ps1: $_" "ERROR"
|
|
}
|
|
}
|
|
|
|
|
|
# Main loop
|
|
do {
|
|
Show-Menu
|
|
$choice = Read-Host "Select an option (1-7)"
|
|
|
|
switch ($choice) {
|
|
"1" { Set-HighPerformancePowerPlan }
|
|
"2" { Rename-PCToMac }
|
|
"3" {
|
|
Set-HighPerformancePowerPlan
|
|
Rename-PCToMac
|
|
}
|
|
"4" { Install-CommonTools }
|
|
"5" { Apply-SystemTweaks }
|
|
"6" { Run-MagicisInstall }
|
|
"7" { Write-Host "`nExiting..." -ForegroundColor Yellow }
|
|
default { Write-Host "`nInvalid option. Please try again." -ForegroundColor Red }
|
|
}
|
|
|
|
if ($choice -notin @("7")) {
|
|
Pause
|
|
}
|
|
|
|
} while ($choice -ne "7")
|