Set-StrictMode -Version Latest $ProgressPreference = 'SilentlyContinue' $ErrorActionPreference = 'Stop' trap { Write-Host "ERROR: $_" ($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$', 'ERROR: $1' | Write-Host ($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$', 'ERROR EXCEPTION: $1' | Write-Host Exit 1 } # remove the sshd host keys. Write-Host 'Removing the sshd host keys...' Remove-Item -Force C:\ProgramData\ssh\ssh_host_* # reset cloudbase-init. Write-Host 'Resetting cloudbase-init...' Remove-Item 'C:\Program Files\Cloudbase Solutions\Cloudbase-Init\log\*.log' # create the sysprep unattended.xml file. $unattendPath = 'C:/Windows/System32/Sysprep/provision-generalize-unattended.xml' # see https://github.com/rgl/vagrant-windows-sysprep/blob/master/lib/vagrant-windows-sysprep/unattend.xml Set-Content -Encoding UTF8 -Path $unattendPath -NoNewLine -Value @" 1 true true en-US en-US en-US en-US true true true true true Home 1 "@ # sysprep the machine. # see https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-setup-states?view=windows-10 Write-Host 'Syspreping the machine...' C:/Windows/System32/Sysprep/Sysprep.exe ` /mode:vm ` /oobe ` /generalize ` /quiet ` /quit ` "/unattend:$unattendPath" ` | Out-String -Stream