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 10, 2025
1 parent 1004baf commit 785f8f1
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 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 @@ -48,6 +52,22 @@ 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 /Cleanup-Image /StartComponentCleanup /ResetBase

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

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

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 785f8f1

Please sign in to comment.