none
Script to inject COMPUTERNAME variable in to sysprep process for Windows 10 RRS feed

  • Question

  • Hello everybody,

    When deploying Windows 7 images via WDS, I have used EditUnattend.vbs (code below) to prompt to inject a COMPUTERNAME variable in to the sysprep process to the corresponding COMPUTERNAME setting in the;

    4 specialize - amd64_Microsoft-Windows-Shell-Seup-Neutral

    It works absolutely perfectly - Every time. I use sysprep /generalize /oobe /unattend:unattend.xml /quit then use the following registry command to add the call to the EditUnattend.vbs file;

    reg add HKLM\System\Setup /v CmdLine /t REG_SZ /d "cmd /c cscript //nologo C:\windows\setup\scripts\EditUnattend.vbs" /f

    I then capture the image via WDS and re-deploy it as and when necessary.

    With Windows 10, however, it generates the error: Windows Could not parse or process unattend answer file [C:\Windows\Panther\unattend.xml] for pass [specialize]. The answer file is invalid.

    Having read various posts about the error above, it would seem like a common problem related to trying to customize the Windows 10 host name without using the wildcard <ComputerName>*</ComputerName>
    to let sysprep allocate a hostname itself. Not necessarily a problem with the EditUnnatend.vbs file I have previously used. The file is called and I am prompted to enter my desired hostname.

    I am doing this with a VM using snapshots and because of this failure It cases the VM to go in to a reboot loop so I can't check the unattend.xml output.

    I created and verified a brand new unattend.xml for the Windows 10 deployment using Windows System Image Manager.

    So, has anyone managed to get this to work or has another approach to the problem? (other than SSCM sequencing or MDT)

    EditUnattend.vbs

    Do While answer <> vbYes
       computerName = InputBox("Enter the desired Computer Name:", "Computer Name")
       answer = MsgBox("Is this correct?" & vbCrLf & "Computer Name: " & computerName, vbYesNo, "Verify Name")
    Loop

    If fso.FileExists(unattendFile) = False Then
       wscript.echo "ERROR: Could not find the unattend file"
    Else
       'Read the unattend file in and replace apprpriate variables
       Set unattendFileObject = fso.OpenTextFile(unattendFile, 1)
       strContents = unattendFileObject.ReadAll
       strContents = Replace(strContents, "COMPUTERNAME", computerName)
       unattendFileObject.Close

       'Write the updated contents back to the unattend file
       Set unattendFileObject = fso.OpenTextFile(unattendFile, 2)
       unattendFileObject.Write(strContents)
       unattendFileObject.Close
    End If

    ' Launch setup (will use the modified unattend.xml)
    WScript.Sleep 5000
    WshShell.Run "%WINDIR%\System32\oobe\windeploy.exe", 0, True
    Friday, April 8, 2016 2:46 PM

Answers

  • OK, so here is how I have gotten around this challenge.

    I have created an Unattend.xml file with various answers including adding the machine to the domain. This works very well. I can provide the unattend.xml file if anyone wants it?

    I have also created a SetupComplete.cmd file which I call from a RunOnce registry key. The SetupComplete.cmd calls a powershell script called 'hostname-change.ps1'. I am referencing it from a RunOnce registry key because it wouldn't execute properly via the SetupComplete.cmd file, so I have ignored it. Both scripts are listed below. At the point where the RunOnce executes, it prompts for the entry of a new hostname then prompts for a reboot. 

    SetupComplete.cmd

    powershell.exe -command "Set-ExecutionPolicy RemoteSigned -Force"
    powershell.exe -command c:\Windows\Setup\Scripts\hostname-change.ps1
    powershell.exe -command "Set-ExecutionPolicy Restricted -Force"
    del /q /f c:\Windows\Setup\Scripts\hostname-change.ps1 
    del /q /f c:\windows\system32\sysprep\Win10_unattend_desktop.xml 
    del /q /f c:\windows\panther\unattend.xml 
    

    hostname-change.ps1

    $TargetComp=Read-Host -Prompt "Enter the name of this PC (use localhost if unknown) "
    
    $Credential=Get-Credential
    $computerName = GWMI Win32_ComputerSystem -computername $TargetComp -Authentication 6
    Write-host "Current Computer Name is " $computerName
    $name = Read-Host -Prompt "Please Enter new name of this PC."
    Write-host "New Computer Name " $Name
    $Go=Read-Host -prompt "Proceed with computer name change? (Y / N)"
    If(($Go-eq"Y")-or($Go-eq"y"))
    {
    $computername.Rename($name,$credential.GetNetworkCredential().Password,$credential.Username)
    }
    $Reboot=Read-host -Prompt "Do you must restart the PC for the changes to take effect. Restart now? (Y / N)"
    If(($Reboot-eq"Y")-or($Reboot-eq"y"))
    {
    restart-computer -computername $TargetComp
    }

    • Marked as answer by Maw2-D2 Thursday, June 9, 2016 1:58 PM
    Thursday, June 9, 2016 1:58 PM

All replies

  • We have two approaches:

    Similar to what you have above, we have a placeholder name in our template unattend.xml. If the name can be determined during the PE boot stage, we replace that placeholder with the final name before applying it to the disk using DISM.

    Alternatively, if we don't have enough info to work out the name during PE boot, we allow the specialise pass to make up a random name (replace the placeholder value with *). Then in the post-imaging scripts, once we have enough info to know what the name should be, we rename the computer using a thirdparty tool, and only then proceed with the domain join and the rest of the post-imaging process.

    Friday, April 8, 2016 3:11 PM
  • Hey Mike!

    I recently configured a perfectly working reference image and also have one side step of not being able to inject a custom name like I used to with Windows 7.

    I am a little lost with your post, but if you could clarify how and or where to use your above method with my Sysprep process I would be ever grateful.

    Currently I seal with Sysprep, and capture a "Master Image" .. When I deploy all is well running my current unattend.xml file, but of course there is no prompt to name computer anymore.

    I can be reached directly at dylan.savenkoff@sait.ca if that would help better.

    Thanks a tonne! :)

    Dylan S

    Tuesday, April 12, 2016 12:15 AM
  • In short, we have a customised WinPE boot with our own scripting. So, the unattend.xml for a given OS version is used as a template, rather than as-is, and we can replace the placeholder values in it with the appropriate one for the install being done.

    e.g. A staff install would be interactive, and prompt the user for various things, and auto-detect some others (such as the asset number from the BIOS). If that is sufficient to come up with the final computername, we can generate an unattend.xml on the fly based on the template (using sed to replace the placeholder values with the specific values needed for this install), apply the image to the drive using dism, and then apply the xml to the resulting drive using dism.

    So, our install process (on the staff side, much simplified) is roughly this

    1. Boot into your WinPE setup.
    2. Ask the user whatever questions are needed
    3. Generate an unattend.xml from the template based on the answers to those questions, using sed to replace the placeholder values with the values needed for this PC.
    4. Apply the appropriate image to the disk using dism /apply
    5. Apply the resulting unattend.xml to the disk using dism /image:c: /apply-unattend:unattend.xml
    Tuesday, April 12, 2016 9:08 AM
  • OK, so here is how I have gotten around this challenge.

    I have created an Unattend.xml file with various answers including adding the machine to the domain. This works very well. I can provide the unattend.xml file if anyone wants it?

    I have also created a SetupComplete.cmd file which I call from a RunOnce registry key. The SetupComplete.cmd calls a powershell script called 'hostname-change.ps1'. I am referencing it from a RunOnce registry key because it wouldn't execute properly via the SetupComplete.cmd file, so I have ignored it. Both scripts are listed below. At the point where the RunOnce executes, it prompts for the entry of a new hostname then prompts for a reboot. 

    SetupComplete.cmd

    powershell.exe -command "Set-ExecutionPolicy RemoteSigned -Force"
    powershell.exe -command c:\Windows\Setup\Scripts\hostname-change.ps1
    powershell.exe -command "Set-ExecutionPolicy Restricted -Force"
    del /q /f c:\Windows\Setup\Scripts\hostname-change.ps1 
    del /q /f c:\windows\system32\sysprep\Win10_unattend_desktop.xml 
    del /q /f c:\windows\panther\unattend.xml 
    

    hostname-change.ps1

    $TargetComp=Read-Host -Prompt "Enter the name of this PC (use localhost if unknown) "
    
    $Credential=Get-Credential
    $computerName = GWMI Win32_ComputerSystem -computername $TargetComp -Authentication 6
    Write-host "Current Computer Name is " $computerName
    $name = Read-Host -Prompt "Please Enter new name of this PC."
    Write-host "New Computer Name " $Name
    $Go=Read-Host -prompt "Proceed with computer name change? (Y / N)"
    If(($Go-eq"Y")-or($Go-eq"y"))
    {
    $computername.Rename($name,$credential.GetNetworkCredential().Password,$credential.Username)
    }
    $Reboot=Read-host -Prompt "Do you must restart the PC for the changes to take effect. Restart now? (Y / N)"
    If(($Reboot-eq"Y")-or($Reboot-eq"y"))
    {
    restart-computer -computername $TargetComp
    }

    • Marked as answer by Maw2-D2 Thursday, June 9, 2016 1:58 PM
    Thursday, June 9, 2016 1:58 PM
  • Check out my answer if you want an easy way to achieve the end result...
    Thursday, June 9, 2016 2:52 PM
  • Maw2-D2. i know its been a while, but do you still have/ would you mind sharing your unattend.xml that you used with the above files?

    Thanks in advance.

    Saturday, October 13, 2018 2:17 PM
  • Maw2-D2. i know its been a while, but do you still have/ would you mind sharing your unattend.xml that you used with the above files?

    Thanks in advance.

    Indeed for me the same, if you want to share, Great

    Thank you

    Thursday, November 8, 2018 6:26 PM
  • can you share the unattend.xml?
    Thursday, June 13, 2019 10:50 PM
  • Hello, if you still have the unattend.xml file that will prompt for computer name and add to domain will be greatly appreciate it.  I know it is quite awhile lol.

    jluna@laredoisd.org

    Thanks, 

    Joe 

    Monday, June 17, 2019 10:02 PM
  • Hello friend, were you able to get the Maw2-D2 unattend.xml?

    Joe Luna

    Tuesday, July 16, 2019 1:12 PM