From 8f31c8bd2c14491e61caec853884d5ed2c72d147 Mon Sep 17 00:00:00 2001 From: Christian Ohlsson Date: Thu, 10 Sep 2026 10:52:16 +0200 Subject: [PATCH] =?UTF-8?q?Nu=20k=C3=B6r=20den=20=C3=A4ven=20en=20Disk=20C?= =?UTF-8?q?leanup=20efter=C3=A5t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uppdatera_windows.ps1 | 54 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/uppdatera_windows.ps1 b/uppdatera_windows.ps1 index f4d790a..7fff09d 100644 --- a/uppdatera_windows.ps1 +++ b/uppdatera_windows.ps1 @@ -1,12 +1,18 @@ Write-Host "=== Windows-underhåll startar ===" -ForegroundColor Green +Write-Host "" + +# Diskutrymme före +$diskBefore = (Get-PSDrive C).Free / 1GB Write-Host "Uppdaterar Winget-källor..." -ForegroundColor Green winget source update +Write-Host "" Write-Host "Installerar Winget-uppdateringar..." -ForegroundColor Green + winget upgrade --all ` - --accept-package-agreements ` - --accept-source-agreements + --accept-package-agreements ` + --accept-source-agreements Write-Host "" Write-Host "Installerar Windows Updates..." -ForegroundColor Green @@ -16,9 +22,38 @@ Import-Module PSWindowsUpdate -ErrorAction SilentlyContinue Get-WindowsUpdate -Install -AcceptAll -IgnoreReboot Write-Host "" -Write-Host "Diskutrymme:" -ForegroundColor Green +Write-Host "Rensar gamla Windows-komponenter..." -ForegroundColor Green -Get-PSDrive C +DISM /Online /Cleanup-Image /StartComponentCleanup /ResetBase + +Write-Host "" +Write-Host "Rensar temporära filer..." -ForegroundColor Green + +Remove-Item "$env:TEMP\*" ` + -Recurse ` + -Force ` + -ErrorAction SilentlyContinue + +Remove-Item "C:\Windows\Temp\*" ` + -Recurse ` + -Force ` + -ErrorAction SilentlyContinue + +Write-Host "Temporära filer rensade." -ForegroundColor Green + +Write-Host "" +Write-Host "Rensar Windows Update-cache..." -ForegroundColor Green + +Stop-Service wuauserv -Force -ErrorAction SilentlyContinue + +Remove-Item "C:\Windows\SoftwareDistribution\Download\*" ` + -Recurse ` + -Force ` + -ErrorAction SilentlyContinue + +Start-Service wuauserv + +Write-Host "Windows Update-cache rensad." -ForegroundColor Green Write-Host "" Write-Host "Kontrollerar om fler Winget-uppdateringar finns..." -ForegroundColor Green @@ -27,9 +62,20 @@ winget upgrade Write-Host "" +# Diskutrymme efter +$diskAfter = (Get-PSDrive C).Free / 1GB +$freed = $diskAfter - $diskBefore + +Write-Host "Diskutrymme före : $([Math]::Round($diskBefore,2)) GB" oundColor Cyan +Write-Host "Diskutrymme efter : $([Math]::Round($diskAfter,2)) GB" -undColor Cyan +Write-Host "Frigjort utrymme : $([Math]::Round($freed,2)) GB" -ForegroundColor Yellow-Host "" + if (Get-WURebootStatus -Silent) { Write-Host "⚠ Systemet behöver startas om." -ForegroundColor Yellow } +else { + Write-Host "✅ Ingen omstart krävs." -ForegroundColor Green +} Write-Host "" Write-Host "=== Windows-underhåll klart ===" -ForegroundColor Green \ No newline at end of file