diskpart didn't work in unattended sysprep

244 Views Asked by At

I run sysprep with an answer file, which runs a batch script in the specialize configuration pass. The batch script gets the target HDD index, and runs diskpart against that HDD.

All files are located in C:\temp:

C:\temp\unattend.xml  
C:\temp\testdisk.bat  
C:\temp\1.txt  
C:\temp\2.txt

I run sysprep using an unattend answer like this:

sysprep /generalize /oobe /reboot unattend:c:\temp\unattend.xml

The unattend.xml looks lihe this:

<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
    <settings pass="specialize">
        <component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <RunAsynchronous>
                <RunAsynchronousCommand wcm:action="add">
                    <Order>1</Order>
                    <Path>C:\Temp\testdisk.bat</Path>
                    <Description>test</Description>
                </RunAsynchronousCommand>
            </RunAsynchronous>
        </component>
    </settings>
    <cpi:offlineImage cpi:source="wim:E:\installwin10pro.wim#Windows 10 Pro" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>

The testdisk.bat looks like this:

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

md c:\temp\testdir1

set "params=%*"

cd /d "%~dp0" && ( if exist "c:\temp\getadmin.vbs" del "c:\temp\getadmin.vbs" ) && fsutil dirty query C: 1>nul 2>nul || (  echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/c cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> c:\temp\getadmin.vbs" && "c:\temp\getadmin.vbs" && exit /B )

Set "Index="
For /F "Tokens=2 Delims==" %%G In ('%SystemRoot%\System32\wbem\WMIC.exe
 DiskDrive Where "Model Like 'ST%%' And Size > 300000000000" Get Index
 /Value 2^>NUL') Do For %%H In (%%G) Do Set "Index=%%H"
If Not Defined Index GoTo :EOF

Echo Your Disk Index is %Index%

md c:\temp\testdir2

echo select disk %index% > 1.txt

type 2.txt >> 1.txt

diskpart /s c:\temp\1.txt

Pause

C:\temp\1.txt is empty for holding the index of the HDD.

C:\temp\2.txt looks like below:

clean
convert gpt
create partition primary size = 1000
format quick fs=ntfs
assign
create partition primary size = 1000
format quick fs=ntfs
assign

Finally, when getting into the OS, I checked, the batch script created testdir1 and testdir2, contents of 2.txt is attached to the end of 1.txt which looks like below:

select disk 1
clean
convert gpt
create partition primary size = 1000
format quick fs=ntfs
assign
create partition primary size = 1000
format quick fs=ntfs
assign

But diskpart does not appear to have been run.

I tried to run diskpart /s 1.txt after the installation, and it works well, but why did it not work in the unattend setup process?

Could someone point out where the problem is?

0

There are 0 best solutions below