# system-tools.ps1 - Menú interactivo con test de rendimiento # Ejecutar como Administrador en Windows param( [switch]$SkipAdminCheck ) # ======================================== # 1. Verificación de privilegios (CORREGIDO) # ======================================== function Test-IsAdmin { if ($PSVersionTable.PSEdition -eq 'Core' -and ($IsLinux -or $IsMacOS)) { return (id -u 2>$null) -eq 0 } else { $currentPrincipal = New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent() ) return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) } } if (-not $SkipAdminCheck -and -not (Test-IsAdmin)) { Write-Host "`n❌ Este script requiere privilegios de Administrador." -ForegroundColor Red Write-Host " ➜ Click derecho en PowerShell → 'Ejecutar como administrador'`n" -ForegroundColor Yellow Start-Sleep -Seconds 3 exit 1 } # ======================================== # 2. Obtener información del sistema # ======================================== function Get-SystemInfo { $info = @{} if ($IsLinux -or $IsMacOS) { $info.Sistema = "Linux/MacOS" $info.Hostname = $(hostname 2>$null) $info.Kernel = $(uname -r 2>$null) $info.Arquitectura = $(uname -m 2>$null) $info.Usuario = $(whoami 2>$null) $info.IP = $(hostname -I 2>$null).Trim() } else { $computer = Get-ComputerInfo $info.Sistema = "Windows $($computer.WindowsProductName) $($computer.WindowsVersion)" $info.Hostname = $computer.CsName $info.Usuario = "$($computer.CsDomain)\$($computer.CsUserName)" $info.Arquitectura = $computer.CsSystemType $info.RAM_Total = "{0:N1} GB" -f ($computer.OsTotalVisibleMemorySize / 1MB) $disk = Get-PSDrive C -ErrorAction SilentlyContinue if ($disk) { $free = [math]::Round($disk.Free / 1GB, 2) $total = [math]::Round(($disk.Used + $disk.Free) / 1GB, 2) $info.Disco = "$free GB libres de $total GB" } $ip = Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue | Where-Object { $_.InterfaceAlias -notlike '*Loopback*' -and $_.AddressState -eq 'Preferred' } | Select-Object -First 1 $info.IP = if ($ip) { $ip.IPAddress } else { "No disponible" } } return $info } # ======================================== # 3. Test de rendimiento del sistema (OPCIÓN 3) # ======================================== function Test-SystemPerformance { Clear-Host Write-Host "`n╔════════════════════════════════════════════════════════════╗" -ForegroundColor Magenta Write-Host "║ 3. Test de Rendimiento del Dispositivo ║" -ForegroundColor Magenta Write-Host "╚════════════════════════════════════════════════════════════╝`n" -ForegroundColor Magenta Write-Host "⏳ Analizando hardware...`n" -ForegroundColor Cyan Start-Sleep -Seconds 1 # Disco Duro Write-Host "💾 DISCO DURO" -ForegroundColor Yellow Write-Host ("─" * 55) -ForegroundColor DarkGray $disco = Get-PhysicalDisk | Select-Object -First 1 if ($disco) { $tipoDisco = switch ($disco.MediaType) { "SSD" { "SSD (rápido)" } "HDD" { "HDD (mecánico)" } default { $disco.MediaType } } Write-Host " Modelo : $($disco.FriendlyName)" -ForegroundColor White Write-Host " Tipo : $tipoDisco" -ForegroundColor White Write-Host " Capacidad : $([math]::Round($disco.Size / 1TB, 2)) TB" -ForegroundColor White } else { Write-Host " Información no disponible" -ForegroundColor Red } # Memoria RAM Write-Host "`n🧠 MEMORIA RAM" -ForegroundColor Yellow Write-Host ("─" * 55) -ForegroundColor DarkGray $ram = Get-CimInstance Win32_PhysicalMemory $totalRAM = ($ram | Measure-Object -Property Capacity -Sum).Sum / 1GB $slots = $ram.Count $velocidad = if ($ram -and $ram[0].ConfiguredClockSpeed) { "$($ram[0].ConfiguredClockSpeed) MHz" } else { "Desconocida" } Write-Host " Total : $([math]::Round($totalRAM, 1)) GB" -ForegroundColor White Write-Host " Slots usados : $slots" -ForegroundColor White Write-Host " Velocidad : $velocidad" -ForegroundColor White # Procesador Write-Host "`n⚙️ PROCESADOR (CPU)" -ForegroundColor Yellow Write-Host ("─" * 55) -ForegroundColor DarkGray $cpu = Get-CimInstance Win32_Processor | Select-Object -First 1 $nucleosTotales = (Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors Write-Host " Modelo : $($cpu.Name)" -ForegroundColor White Write-Host " Núcleos : $nucleosTotales lógicos" -ForegroundColor White Write-Host " Velocidad : $($cpu.MaxClockSpeed) MHz" -ForegroundColor White # Tarjeta Gráfica Write-Host "`n🎮 TARJETA GRÁFICA (GPU)" -ForegroundColor Yellow Write-Host ("─" * 55) -ForegroundColor DarkGray $gpu = Get-CimInstance Win32_VideoController | Select-Object -First 1 if ($gpu) { Write-Host " Modelo : $($gpu.Name)" -ForegroundColor White Write-Host " Memoria VRAM : $([math]::Round($gpu.AdapterRAM / 1GB, 1)) GB" -ForegroundColor White } else { Write-Host " Información no disponible" -ForegroundColor Red } # Puntaje Windows (WEI) Write-Host "`n⭐ PUNTUACIÓN WINDOWS (WEI)" -ForegroundColor Yellow Write-Host ("─" * 55) -ForegroundColor DarkGray $weiFile = Get-ChildItem "C:\Windows\Performance\WinSAT\DataStore\" -Filter "Formal.Assessment (*).WinSAT.xml" -ErrorAction SilentlyContinue | Sort-Object LastWriteTime -Descending | Select-Object -First 1 if ($weiFile) { try { [xml]$xml = Get-Content $weiFile.FullName $baseScore = $xml.WinSAT.WinSPR.BaseScore Write-Host " Puntuación Base : $baseScore / 10.0" -ForegroundColor Green # Subscores si existen $subs = @() if ($xml.WinSAT.WinSPR.CPUScore) { $subs += " └─ CPU : $($xml.WinSAT.WinSPR.CPUScore) / 10.0" } if ($xml.WinSAT.WinSPR.MemoryScore) { $subs += " └─ RAM : $($xml.WinSAT.WinSPR.MemoryScore) / 10.0" } if ($xml.WinSAT.WinSPR.GraphicsScore) { $subs += " └─ Gráficos : $($xml.WinSAT.WinSPR.GraphicsScore) / 10.0" } if ($xml.WinSAT.WinSPR.DiskScore) { $subs += " └─ Disco : $($xml.WinSAT.WinSPR.DiskScore) / 10.0" } $subs | ForEach-Object { Write-Host $_ -ForegroundColor White } Write-Host "`n ℹ️ Última evaluación: $($weiFile.LastWriteTime.ToString('dd/MM/yyyy'))" -ForegroundColor DarkGray } catch { Write-Host " ⚠️ Puntuación disponible pero no legible" -ForegroundColor Yellow } } else { Write-Host " ⚠️ No disponible en Windows 10/11" -ForegroundColor Yellow Write-Host " 💡 Ejecutando 'winsat formal' como Admin" -ForegroundColor Cyan winsat formal Write-Host " ⏱️ (El test tarda 5-10 minutos)" -ForegroundColor Red } Write-Host "`n`n[Presiona Enter para volver al menú]" -ForegroundColor DarkGray Read-Host | Out-Null } # ======================================== # 4. Mostrar menú principal # ======================================== function Show-Menu { Clear-Host Write-Host "`n╔════════════════════════════════════════════════╗" -ForegroundColor Cyan Write-Host "║ Herramientas del Sistema v1.4 ║" -ForegroundColor Cyan Write-Host "╚════════════════════════════════════════════════╝" -ForegroundColor Cyan Write-Host "`n📋 Menú de opciones:" Write-Host " ┌────────────────────────────────────┐" -ForegroundColor DarkGray Write-Host " │ 1. Información básica del sistema │" -ForegroundColor Yellow Write-Host " │ 2. Hello World! │" -ForegroundColor Yellow Write-Host " │ 3. Test de rendimiento │" -ForegroundColor Yellow Write-Host " │ 0. Salir │" -ForegroundColor Yellow Write-Host " └────────────────────────────────────┘" -ForegroundColor DarkGray Write-Host "`n ➜ Elige una opción [0-3]: " -ForegroundColor Green -NoNewline } # ======================================== # 5. Ejecución principal # ======================================== function Main { do { Show-Menu $option = (Read-Host).Trim() # ✅ CORREGIDO: Paréntesis obligatorios switch ($option) { '1' { Clear-Host Write-Host "`n╔═══════════════════════════════════════════════╗" -ForegroundColor Magenta Write-Host "║ 1. Información básica del sistema ║" -ForegroundColor Magenta Write-Host "╚═══════════════════════════════════════════════╝`n" -ForegroundColor Magenta $info = Get-SystemInfo foreach ($key in $info.Keys) { if ($info[$key]) { Write-Host " • $($key.PadRight(15)) : $($info[$key])" -ForegroundColor White } } Write-Host "`n`n[Presiona Enter para volver al menú]" -ForegroundColor DarkGray Read-Host | Out-Null } '2' { Clear-Host Write-Host "`n╔════════════════════════════╗" -ForegroundColor Green Write-Host "║ 2. Hello World! ║" -ForegroundColor Green Write-Host "╚════════════════════════════╝`n" -ForegroundColor Green Write-Host " ¡Hola desde PowerShell! 🚀" -ForegroundColor Cyan Write-Host " Ejecutado como Administrador ✅`n" -ForegroundColor Cyan Write-Host "[Presiona Enter para volver al menú]" -ForegroundColor DarkGray Read-Host | Out-Null } '3' { Test-SystemPerformance } '0' { Clear-Host Write-Host "`n👋 ¡Hasta luego!`n" -ForegroundColor Green exit 0 } default { if ($option -ne '') { Write-Host "`n⚠️ Opción inválida. Selecciona 0, 1, 2 o 3." -ForegroundColor Red Start-Sleep -Seconds 1.5 } } } } while ($true) } # ======================================== # 6. Punto de entrada # ======================================== Write-Host "`n🚀 Iniciando herramientas del sistema..." -ForegroundColor Cyan Start-Sleep -Milliseconds 500 Main