Skip to content

Commit

Permalink
scripts: Add cleanup code for Windows guests
Browse files Browse the repository at this point in the history
Signed-off-by: Tu Dinh <[email protected]>
  • Loading branch information
Tu Dinh committed Jan 14, 2025
1 parent 8070530 commit 39f583f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion scripts/guests/windows/install-autotest.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#Requires -RunAsAdministrator

[CmdletBinding()]
param (
[Parameter()]
[switch]$NoNetReporting
[switch]$NoNetReporting,
[Parameter()]
[switch]$Cleanup
)

$ErrorActionPreference = "Stop"
Expand Down Expand Up @@ -52,6 +56,23 @@ if (!$NoNetReporting) {
Register-ScheduledTask -InputObject $task -TaskName "XCP-ng Test Network Report"
}

if ($Cleanup) {
Read-Host -Prompt "Unplug Internet, run Disk Cleanup and continue"

Write-Output "Cleaning up component store"
dism.exe /Online /Cleanup-Image /StartComponentCleanup /ResetBase

Write-Output "Cleaning up SoftwareDistribution"
Stop-Service wuauserv, BITS -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "$env:windir\SoftwareDistribution\Download\*"

Write-Output "Cleaning up Defender signatures"
& "$env:ProgramFiles\Windows Defender\MpCmdRun.exe" -RemoveDefinitions -All

Write-Output "Optimizing system drive"
defrag.exe $env:SystemDrive /O
}

Write-Output "Resealing"
Stop-Process -Name sysprep -ErrorAction SilentlyContinue
& "$env:windir\System32\Sysprep\sysprep.exe" /generalize /oobe /shutdown /unattend:$PSScriptRoot\unattend.xml

0 comments on commit 39f583f

Please sign in to comment.