Skip to content

Instantly share code, notes, and snippets.

@tmeckel
Last active December 29, 2018 14:35
Show Gist options
  • Save tmeckel/1723bffb89159ebdec568684570b0966 to your computer and use it in GitHub Desktop.
Save tmeckel/1723bffb89159ebdec568684570b0966 to your computer and use it in GitHub Desktop.
Create Windows VM Image (disk)

VirtualBox: Create Windows VM Image (disk)

Important Use a VDI disk. Otherwise VBoxManage.execannot shrink the disk!

  1. Install Windows
  2. sconfig.exe
    a. Set updates to manual
    b. Enabled RDP
  3. Install-Module PSWindowsUpdate (Ensure that the machine is able to access www.psgallery.com)
  4. Install-WindowsUpdate -Install -AcceptAll -Confirm:$false or use Get-WindowsUpdate to get a list of missing updates. And install via Install-WindowsUpdate -Install -KBArticleID #KB-Number# -Confirm:$false
  5. 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'
  6. Cleanup image
    a. Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
    b. Dism.exe /online /Cleanup-Image /SPSuperseded
  7. Defragment image defrag.exe $env:SYSTEMDRIVE -w -f -v
  8. Zero all unused sectors of the disk sdelete.exe $env:SYSTEMDRIVE -z
  9. sysprep Image
  10. Shrink disk VBoxManage.exe modifymedium disk "C:\path\to\disk.vdi" --compact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment