none
Sysprep Windows 7 on bare metal and Hyper-V

    Question

  • I am running Hyper-V on Windows 8.1 Enterprise. I migrated my laptop's Windows 7 OS to VM and was able to boot to it in Hyper-V. I cloned my laptop first then sysprepped it with an unattend script and a batch file. The unattend install works and the batch file runs during Windows setup on my bare metal laptop. When I do the same in Hyper-V, the batch file never runs.

    Here's the process I took to migrate my laptop to VM and what I did to get it to run in Hyper-V to see if something along the way I messed something up:

    -Used dism to capture the image.
    -Applied the image to a vhdx.
    -Attach the vhdx in Disk Management.
    -Copied my unattend.bat, unattend.xml, and setup.bat scripts to the C: drive of the vhdx.
    -Loaded the SYSTEM HIVE from the vhdx in Regedit.
    -Changed the "Start" DWORD from 3 to 0 in "HKEY_LOCAL_MACHINE/test/ControlSet001/services/atapi", "HKEY_LOCAL_MACHINE/test/ControlSet001/services/intelide", and "HKEY_LOCAL_MACHINE/test/ControlSet001/services/msahci"
    -Unloaded the SYSTEM HIVE and detached the vhdx.
    -Used Hyper-V to create a Generation 1 VM. Used the vhdx as the disk.
    -Booted the machine up with error, but got rid of it by running a repair on Windows.

    Here are the scripts that I am running during sysprep:

    setup.bat:

    echo. >> "C:\Windows\Setup\scripts\SetupComplete.cmd"
    echo. >> "C:\Windows\Setup\scripts\SetupComplete.cmd"
    echo wmic useraccount where name='Administrator' rename 'admin' >> "C:\Windows\Setup\scripts\SetupComplete.cmd"
    msdtc -uninstall
    msdtc -install
    net start msdtc
    c:\windows\system32\sysprep\sysprep /oobe /generalize /reboot /unattend:c:\unattend.xml
    reg add HKLM\System\Setup /v CmdLine /t REG_SZ /d "C:\unattend.bat" /f
    shutdown /f /r /t 0
    =======================================

    The unattend.bat just names the machine:

    @echo off
    setlocal EnableDelayedExpansion
    cd windows\panther

    set /p Variable=Enter The Computer Name:

    (for /F "delims=" %%a in (unattend.xml) do (
       set "line=%%a"
       set "newLine=!line:ComputerName>=!"
       if "!newLine!" neq "!line!" (
          set "newLine=<ComputerName>%Variable%</ComputerName>"
       )
       echo !newLine!
    )) > newunattend.xml
    copy /y newunattend.xml unattend.xml && del newunattend.xml
    "%WINDIR%\System32\oobe\windeploy.exe", 0, True
    cd\
    del unattend.bat
    del "windows\panther\unattend.xml"
    =======================================

    The unattend.bat never runs in the VM, but does run on the bare metal laptop. Can anyone figure out why my script won't run? I have also did a clean install in Hyper-V then sysprepped it, but the script never runs either. Thanks.

    Note: .bat files don't run, but .vbs do run, but does rename the machine in VM.

    Friday, September 25, 2015 12:59 PM

Answers

  • Hi Lytvinh,

    I recommend you post this in Hyper-V forum also, as they should have more professional knowledge on Hyper-v and you may get effective solution timely.

    Best regards,


    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Niko Cheng
    TechNet Community Support

    Monday, September 28, 2015 7:18 AM

All replies

  • Hi Lytvinh,

    I recommend you post this in Hyper-V forum also, as they should have more professional knowledge on Hyper-v and you may get effective solution timely.

    Best regards,


    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Niko Cheng
    TechNet Community Support

    Monday, September 28, 2015 7:18 AM
  • I had a feeling I was in the wrong forum. Thanks Niko.
    Monday, September 28, 2015 12:16 PM