OptimizarPC

Gerador de scripts PowerShell para Windows 11

Optimizações

Selecciona o que queres incluir no script

19 activas

🧹Limpeza

4/5

Arranque

2/2

🧠RAM & CPU

4/4

💾Disco

2/2

🌐Rede

3/3

🔧Windows Tweaks

4/4
OptimizarPC.ps1
19 optimizações~5.3 GB26.4 GB estimados
-emerald-400">"text-slate-500">#Requires -RunAsAdministrator
<-emerald-400">"text-slate-500">#
  ____        _   _           _              ____   ____
 / __ \      | | (_)         (_)            |  _ \ / ___|
| |  | |_ __ | |_ _ _ __ ___  _ ______ _ _ _| |_) | |
| |  | | -emerald-400">'_ \| __| | '_ ` _ \| |_  / _` | '__|  __/| |
| |__| | |_) | |_| | | | | | | |/ / (_| | |  | |   | |___
 \____/| .__/ \__|_|_| |_| |_|_/___\__,_|_|  |_|    \____|
       | |
       |_|   Gerador de optimizacoes para Windows 11
-emerald-400">"text-slate-500">#>

-amber-300">$ErrorActionPreference = -emerald-400">'SilentlyContinue'
-amber-300">$ProgressPreference = -emerald-400">'SilentlyContinue'

-emerald-400">"text-slate-500"># Helper para emptyworkingset
-cyan-400">Add-Type -Name psapi -Namespace -emerald-400">'' -MemberDefinition @"
[System.Runtime.InteropServices.DllImport(-emerald-400">"psapi.dll")]
public static extern int EmptyWorkingSet(System.IntPtr hProcess);
"@ -ErrorAction SilentlyContinue

-cyan-400">function -cyan-400">Write-Section(-amber-300">$title) {
    -cyan-400">Write-Host -emerald-400">""
    -cyan-400">Write-Host (-emerald-400">"=" * 70) -ForegroundColor Cyan
    -cyan-400">Write-Host -emerald-400">"  -amber-300">$title" -ForegroundColor Cyan
    -cyan-400">Write-Host (-emerald-400">"=" * 70) -ForegroundColor Cyan
}

-cyan-400">function -cyan-400">Get-SystemState {
    -amber-300">$disk = -cyan-400">Get-PSDrive -Name C
    -amber-300">$os = -cyan-400">Get-CimInstance Win32_OperatingSystem
    -amber-300">$ramFreeGB = [math]::Round(-amber-300">$os.FreePhysicalMemory / 1MB, 2)
    -amber-300">$ramTotalGB = [math]::Round(-amber-300">$os.TotalVisibleMemorySize / 1MB, 2)
    -amber-300">$uptime = (-cyan-400">Get-Date) - -amber-300">$os.LastBootUpTime
    -cyan-400">return [PSCustomObject]@{
        DiscoLivreGB = [math]::Round(-amber-300">$disk.Free / 1GB, 2)
        DiscoTotalGB = [math]::Round((-amber-300">$disk.Free + -amber-300">$disk.Used) / 1GB, 2)
        RAMLivreGB = -amber-300">$ramFreeGB
        RAMTotalGB = -amber-300">$ramTotalGB
        UptimeHoras = [math]::Round(-amber-300">$uptime.TotalHours, 1)
    }
}

-cyan-400">Clear-Host
-cyan-400">Write-Host -emerald-400">""
-cyan-400">Write-Host -emerald-400">"  OptimizarPC — Windows 11" -ForegroundColor Cyan
-cyan-400">Write-Host -emerald-400">"  -------------------------" -ForegroundColor DarkCyan
-cyan-400">Write-Host -emerald-400">""

-amber-300">$inicio = -cyan-400">Get-SystemState
-cyan-400">Write-Host -emerald-400">"  Estado inicial:" -ForegroundColor White
-cyan-400">Write-Host (-emerald-400">"    Disco C: livre   {0} GB / {1} GB" -f -amber-300">$inicio.DiscoLivreGB, -amber-300">$inicio.DiscoTotalGB) -ForegroundColor Gray
-cyan-400">Write-Host (-emerald-400">"    RAM livre        {0} GB / {1} GB" -f -amber-300">$inicio.RAMLivreGB, -amber-300">$inicio.RAMTotalGB) -ForegroundColor Gray
-cyan-400">Write-Host (-emerald-400">"    Uptime           {0} horas" -f -amber-300">$inicio.UptimeHoras) -ForegroundColor Gray
-cyan-400">Write-Host -emerald-400">""
-cyan-400">Start-Sleep -Seconds 1

-cyan-400">Write-Section -emerald-400">"🧹 Limpeza"

-emerald-400">"text-slate-500"># --- Ficheiros temporários (%TEMP%, Prefetch, INetCache) ---
-cyan-400">Write-Host -emerald-400">"→ A limpar ficheiros temporários..." -ForegroundColor Yellow
-cyan-400">Get-ChildItem -Path -emerald-400">"-amber-300">$env:TEMP" -Recurse -Force -ErrorAction SilentlyContinue | -cyan-400">Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
-cyan-400">Get-ChildItem -Path -emerald-400">"C:\Windows\Temp" -Recurse -Force -ErrorAction SilentlyContinue | -cyan-400">Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
-cyan-400">Get-ChildItem -Path -emerald-400">"C:\Windows\Prefetch" -Recurse -Force -ErrorAction SilentlyContinue | -cyan-400">Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
-cyan-400">Get-ChildItem -Path -emerald-400">"-amber-300">$env:LOCALAPPDATA\Microsoft\Windows\INetCache" -Recurse -Force -ErrorAction SilentlyContinue | -cyan-400">Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
-cyan-400">Write-Host -emerald-400">"✓ Ficheiros temporários limpos" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Cache do Windows Update ---
-cyan-400">Write-Host -emerald-400">"→ A limpar cache do Windows Update..." -ForegroundColor Yellow
-cyan-400">Stop-Service -Name wuauserv -Force -ErrorAction SilentlyContinue
-cyan-400">Stop-Service -Name bits -Force -ErrorAction SilentlyContinue
-cyan-400">Remove-Item -emerald-400">"C:\Windows\SoftwareDistribution\Download\*" -Recurse -Force -ErrorAction SilentlyContinue
-cyan-400">Start-Service -Name wuauserv -ErrorAction SilentlyContinue
-cyan-400">Start-Service -Name bits -ErrorAction SilentlyContinue
-cyan-400">Write-Host -emerald-400">"✓ Cache do Windows Update limpa" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Logs de eventos antigos ---
-cyan-400">Write-Host -emerald-400">"→ A limpar logs de eventos antigos..." -ForegroundColor Yellow
wevtutil el | -cyan-400">ForEach-Object { wevtutil cl -emerald-400">"-amber-300">$_" 2>-amber-300">$null }
-cyan-400">Write-Host -emerald-400">"✓ Logs limpos" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Cache de miniaturas (thumbnails) ---
-cyan-400">Write-Host -emerald-400">"→ A limpar cache de miniaturas..." -ForegroundColor Yellow
-cyan-400">Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue
-cyan-400">Remove-Item -emerald-400">"-amber-300">$env:LOCALAPPDATA\Microsoft\Windows\Explorer\thumbcache_*.db" -Force -ErrorAction SilentlyContinue
-cyan-400">Start-Process explorer
-cyan-400">Write-Host -emerald-400">"✓ Cache de miniaturas limpa" -ForegroundColor Green

-cyan-400">Write-Section -emerald-400">"⚡ Arranque"

-emerald-400">"text-slate-500"># --- Desactivar serviços pesados no boot (SysMain, DiagTrack, WSearch) ---
-cyan-400">Write-Host -emerald-400">"→ A desactivar serviços pesados..." -ForegroundColor Yellow
-amber-300">$svcs = @(-emerald-400">'SysMain',-emerald-400">'DiagTrack',-emerald-400">'WSearch')
-cyan-400">foreach (-amber-300">$s in -amber-300">$svcs) {
    -cyan-400">Stop-Service -Name -amber-300">$s -Force -ErrorAction SilentlyContinue
    -cyan-400">Set-Service -Name -amber-300">$s -StartupType Disabled -ErrorAction SilentlyContinue
    -cyan-400">Write-Host -emerald-400">"   • -amber-300">$s desactivado" -ForegroundColor DarkGray
}
-cyan-400">Write-Host -emerald-400">"✓ Serviços pesados desactivados" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Remover apps do arranque automático (Teams, OneDrive, Spotify, Discord) ---
-cyan-400">Write-Host -emerald-400">"→ A remover apps do arranque..." -ForegroundColor Yellow
-amber-300">$names = @(-emerald-400">'Teams',-emerald-400">'OneDrive',-emerald-400">'Spotify',-emerald-400">'Discord',-emerald-400">'MicrosoftTeams')
-cyan-400">foreach (-amber-300">$n in -amber-300">$names) {
    -cyan-400">Get-CimInstance Win32_StartupCommand -ErrorAction SilentlyContinue | -cyan-400">Where-Object { -amber-300">$_.Name -like -emerald-400">"*-amber-300">$n*" } | -cyan-400">ForEach-Object {
        -cyan-400">Remove-ItemProperty -Path -emerald-400">"HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name -amber-300">$_.Name -ErrorAction SilentlyContinue
        -cyan-400">Remove-ItemProperty -Path -emerald-400">"HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" -Name -amber-300">$_.Name -ErrorAction SilentlyContinue
        -cyan-400">Write-Host -emerald-400">"   • $(-amber-300">$_.Name) removido" -ForegroundColor DarkGray
    }
}
-cyan-400">Write-Host -emerald-400">"✓ Apps de arranque limpas" -ForegroundColor Green

-cyan-400">Write-Section -emerald-400">"🧠 RAM & CPU"

-emerald-400">"text-slate-500"># --- Libertar working set dos processos em background ---
-cyan-400">Write-Host -emerald-400">"→ A libertar memória de processos em background..." -ForegroundColor Yellow
-cyan-400">Get-Process | -cyan-400">Where-Object { -amber-300">$_.WorkingSet -gt 50MB -and -amber-300">$_.MainWindowHandle -eq 0 } | -cyan-400">ForEach-Object {
    -cyan-400">try { [void][psapi]::EmptyWorkingSet(-amber-300">$_.Handle) } -cyan-400">catch {}
}
-emerald-400">"text-slate-500"># Fallback usando rundll32
rundll32.exe advapi32.dll,ProcessIdleTasks
-cyan-400">Write-Host -emerald-400">"✓ Working set libertado" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Desactivar hibernação (liberta espaço = tamanho da RAM) ---
-cyan-400">Write-Host -emerald-400">"→ A desactivar hibernação..." -ForegroundColor Yellow
powercfg /hibernate off
-cyan-400">Write-Host -emerald-400">"✓ Hibernação desactivada (hiberfil.sys removido)" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Optimizar scheduling do CPU (prioridade para apps em 1º plano) ---
-cyan-400">Write-Host -emerald-400">"→ A optimizar scheduling do CPU..." -ForegroundColor Yellow
-cyan-400">Set-ItemProperty -Path -emerald-400">"HKLM:\SYSTEM\CurrentControlSet\Control\PriorityControl" -Name -emerald-400">"Win32PrioritySeparation" -Value 38 -Force
-cyan-400">Write-Host -emerald-400">"✓ CPU priorizado para foreground" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Desactivar Game DVR / Xbox Game Bar ---
-cyan-400">Write-Host -emerald-400">"→ A desactivar Game DVR / Game Bar..." -ForegroundColor Yellow
-cyan-400">Set-ItemProperty -Path -emerald-400">"HKCU:\System\GameConfigStore" -Name -emerald-400">"GameDVR_Enabled" -Value 0 -Force -ErrorAction SilentlyContinue
-cyan-400">Set-ItemProperty -Path -emerald-400">"HKLM:\SOFTWARE\Policies\Microsoft\Windows\GameDVR" -Name -emerald-400">"AllowGameDVR" -Value 0 -Force -ErrorAction SilentlyContinue
-cyan-400">Set-ItemProperty -Path -emerald-400">"HKCU:\Software\Microsoft\GameBar" -Name -emerald-400">"UseNexusForGameBarEnabled" -Value 0 -Force -ErrorAction SilentlyContinue
-cyan-400">Write-Host -emerald-400">"✓ Game DVR desactivado" -ForegroundColor Green

-cyan-400">Write-Section -emerald-400">"💾 Disco"

-emerald-400">"text-slate-500"># --- Limpeza avançada (cleanmgr silencioso, todas as categorias) ---
-cyan-400">Write-Host -emerald-400">"→ A executar limpeza avançada (cleanmgr)..." -ForegroundColor Yellow
-amber-300">$keys = -emerald-400">'Active Setup Temp Folders',-emerald-400">'BranchCache',-emerald-400">'Downloaded Program Files',-emerald-400">'Internet Cache Files',-emerald-400">'Memory Dump Files',-emerald-400">'Old ChkDsk Files',-emerald-400">'Previous Installations',-emerald-400">'Recycle Bin',-emerald-400">'Service Pack Cleanup',-emerald-400">'Setup Log Files',-emerald-400">'System error memory dump files',-emerald-400">'System error minidump files',-emerald-400">'Temporary Files',-emerald-400">'Temporary Setup Files',-emerald-400">'Thumbnail Cache',-emerald-400">'Update Cleanup',-emerald-400">'Upgrade Discarded Files',-emerald-400">'Windows Defender',-emerald-400">'Windows Error Reporting Files',-emerald-400">'Windows Upgrade Log Files'
-cyan-400">foreach (-amber-300">$k in -amber-300">$keys) {
    -amber-300">$path = -emerald-400">"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\-amber-300">$k"
    -cyan-400">if (-cyan-400">Test-Path -amber-300">$path) {
        -cyan-400">New-ItemProperty -Path -amber-300">$path -Name -emerald-400">"StateFlags0099" -Value 2 -PropertyType DWord -Force | -cyan-400">Out-Null
    }
}
-cyan-400">Start-Process -FilePath -emerald-400">"cleanmgr.exe" -ArgumentList -emerald-400">"/sagerun:99" -Wait -WindowStyle Hidden
-cyan-400">Write-Host -emerald-400">"✓ Limpeza avançada concluída" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- TRIM para SSD / Defrag para HDD (auto-detectado) ---
-cyan-400">Write-Host -emerald-400">"→ A optimizar discos (TRIM/Defrag)..." -ForegroundColor Yellow
-cyan-400">Get-Volume | -cyan-400">Where-Object { -amber-300">$_.DriveType -eq -emerald-400">'Fixed' -and -amber-300">$_.DriveLetter } | -cyan-400">ForEach-Object {
    -amber-300">$d = -amber-300">$_.DriveLetter
    -cyan-400">Write-Host -emerald-400">"   • A optimizar $(-amber-300">$d):" -ForegroundColor DarkGray
    -cyan-400">Optimize-Volume -DriveLetter -amber-300">$d -ReTrim -Defrag -ErrorAction SilentlyContinue
}
-cyan-400">Write-Host -emerald-400">"✓ Discos optimizados" -ForegroundColor Green

-cyan-400">Write-Section -emerald-400">"🌐 Rede"

-emerald-400">"text-slate-500"># --- Flush DNS + reset Winsock/TCP ---
-cyan-400">Write-Host -emerald-400">"→ A fazer flush DNS e reset TCP/Winsock..." -ForegroundColor Yellow
ipconfig /flushdns | -cyan-400">Out-Null
netsh winsock reset | -cyan-400">Out-Null
netsh int ip reset | -cyan-400">Out-Null
-cyan-400">Write-Host -emerald-400">"✓ DNS e stack TCP/IP reiniciados" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Configurar DNS Cloudflare (1.1.1.1 / 1.0.0.1) ---
-cyan-400">Write-Host -emerald-400">"→ A configurar DNS Cloudflare..." -ForegroundColor Yellow
-cyan-400">Get-NetAdapter | -cyan-400">Where-Object { -amber-300">$_.Status -eq -emerald-400">'Up' } | -cyan-400">ForEach-Object {
    -cyan-400">Set-DnsClientServerAddress -InterfaceIndex -amber-300">$_.ifIndex -ServerAddresses (-emerald-400">"1.1.1.1",-emerald-400">"1.0.0.1") -ErrorAction SilentlyContinue
    -cyan-400">Write-Host -emerald-400">"   • $(-amber-300">$_.Name) → 1.1.1.1 / 1.0.0.1" -ForegroundColor DarkGray
}
-cyan-400">Write-Host -emerald-400">"✓ DNS configurado" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Reduzir latência TCP (desactivar algoritmo de Nagle) ---
-cyan-400">Write-Host -emerald-400">"→ A desactivar algoritmo de Nagle..." -ForegroundColor Yellow
-amber-300">$base = -emerald-400">"HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"
-cyan-400">Get-ChildItem -amber-300">$base | -cyan-400">ForEach-Object {
    -cyan-400">New-ItemProperty -Path -amber-300">$_.PSPath -Name -emerald-400">"TcpAckFrequency" -Value 1 -PropertyType DWord -Force | -cyan-400">Out-Null
    -cyan-400">New-ItemProperty -Path -amber-300">$_.PSPath -Name -emerald-400">"TCPNoDelay" -Value 1 -PropertyType DWord -Force | -cyan-400">Out-Null
}
-cyan-400">Write-Host -emerald-400">"✓ Nagle desactivado" -ForegroundColor Green

-cyan-400">Write-Section -emerald-400">"🔧 Windows Tweaks"

-emerald-400">"text-slate-500"># --- Activar plano de energia Ultimate Performance ---
-cyan-400">Write-Host -emerald-400">"→ A activar Ultimate Performance..." -ForegroundColor Yellow
powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61 | -cyan-400">Out-Null
-amber-300">$guid = (powercfg -list | Select-String -emerald-400">"Ultimate Performance" | -cyan-400">ForEach-Object { (-amber-300">$_ -split -emerald-400">'\s+')[3] } | -cyan-400">Select-Object -First 1)
-cyan-400">if (-amber-300">$guid) { powercfg -setactive -amber-300">$guid }
-cyan-400">Write-Host -emerald-400">"✓ Plano Ultimate Performance activado" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Reduzir telemetria ao mínimo ---
-cyan-400">Write-Host -emerald-400">"→ A reduzir telemetria..." -ForegroundColor Yellow
-cyan-400">Set-ItemProperty -Path -emerald-400">"HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name -emerald-400">"AllowTelemetry" -Value 0 -Force -ErrorAction SilentlyContinue
-cyan-400">Set-ItemProperty -Path -emerald-400">"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection" -Name -emerald-400">"AllowTelemetry" -Value 0 -Force -ErrorAction SilentlyContinue
-cyan-400">Stop-Service -Name DiagTrack -Force -ErrorAction SilentlyContinue
-cyan-400">Set-Service -Name DiagTrack -StartupType Disabled -ErrorAction SilentlyContinue
-cyan-400">Write-Host -emerald-400">"✓ Telemetria minimizada" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Optimizar efeitos visuais para desempenho ---
-cyan-400">Write-Host -emerald-400">"→ A optimizar efeitos visuais..." -ForegroundColor Yellow
-cyan-400">Set-ItemProperty -Path -emerald-400">"HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects" -Name -emerald-400">"VisualFXSetting" -Value 2 -Force
-cyan-400">Set-ItemProperty -Path -emerald-400">"HKCU:\Control Panel\Desktop" -Name -emerald-400">"UserPreferencesMask" -Value ([byte[]](0x90,0x12,0x03,0x80,0x10,0x00,0x00,0x00)) -Force
-cyan-400">Write-Host -emerald-400">"✓ Efeitos visuais optimizados" -ForegroundColor Green

-emerald-400">"text-slate-500"># --- Desactivar notificações de background ---
-cyan-400">Write-Host -emerald-400">"→ A desactivar notificações de background..." -ForegroundColor Yellow
-cyan-400">Set-ItemProperty -Path -emerald-400">"HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications" -Name -emerald-400">"ToastEnabled" -Value 0 -Force -ErrorAction SilentlyContinue
-cyan-400">Set-ItemProperty -Path -emerald-400">"HKCU:\Software\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications" -Name -emerald-400">"GlobalUserDisabled" -Value 1 -Force -ErrorAction SilentlyContinue
-cyan-400">Write-Host -emerald-400">"✓ Notificações background desactivadas" -ForegroundColor Green

-cyan-400">Write-Section -emerald-400">"📊 Sumário"
-amber-300">$fim = -cyan-400">Get-SystemState
-amber-300">$discoGanho = [math]::Round(-amber-300">$fim.DiscoLivreGB - -amber-300">$inicio.DiscoLivreGB, 2)
-amber-300">$ramGanho = [math]::Round(-amber-300">$fim.RAMLivreGB - -amber-300">$inicio.RAMLivreGB, 2)
-cyan-400">Write-Host -emerald-400">""
-cyan-400">Write-Host (-emerald-400">"  Disco livre:  {0} GB  →  {1} GB   ({2:+0.00;-0.00;0} GB)" -f -amber-300">$inicio.DiscoLivreGB, -amber-300">$fim.DiscoLivreGB, -amber-300">$discoGanho) -ForegroundColor White
-cyan-400">Write-Host (-emerald-400">"  RAM livre:    {0} GB  →  {1} GB   ({2:+0.00;-0.00;0} GB)" -f -amber-300">$inicio.RAMLivreGB, -amber-300">$fim.RAMLivreGB, -amber-300">$ramGanho) -ForegroundColor White
-cyan-400">Write-Host -emerald-400">""
-cyan-400">Write-Host -emerald-400">"  Optimização concluída!" -ForegroundColor Green
-cyan-400">Write-Host -emerald-400">""

-amber-300">$resp = -cyan-400">Read-Host -emerald-400">"Reiniciar agora? (s/n)"
-cyan-400">if (-amber-300">$resp -match -emerald-400">'^[sSyY]') {
    -cyan-400">Write-Host -emerald-400">"A reiniciar em 5 segundos..." -ForegroundColor Yellow
    -cyan-400">Start-Sleep -Seconds 5
    -cyan-400">Restart-Computer -Force
} -cyan-400">else {
    -cyan-400">Write-Host -emerald-400">"OK. Recomenda-se reiniciar mais tarde." -ForegroundColor DarkGray
}