Important Use a VDI disk. Otherwise
VBoxManage.exe
cannot shrink the disk!
- Install Windows
sconfig.exe
a. Set updates to manual
b. Enabled RDPInstall-Module PSWindowsUpdate
(Ensure that the machine is able to access www.psgallery.com)Install-WindowsUpdate -Install -AcceptAll -Confirm:$false
or useGet-WindowsUpdate
to get a list of missing updates. And install viaInstall-WindowsUpdate -Install -KBArticleID #KB-Number# -Confirm:$false
- On Windows Server Core set Powershell as the default shell
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name Shell -Value 'PowerShell.exe -NoExit'
- Cleanup image
a.Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
b.Dism.exe /online /Cleanup-Image /SPSuperseded
- Defragment image
defrag.exe $env:SYSTEMDRIVE -w -f -v
- Zero all unused sectors of the disk
sdelete.exe $env:SYSTEMDRIVE -z
- sysprep Image
- Shrink disk
VBoxManage.exe modifymedium disk "C:\path\to\disk.vdi" --compact