Install the required module:

 

On any computer, run powershell with Admin privilege

Install-Module -name AzureAD

Install-Module -name MSOnline

Install-Module -name MSGraph

Install-module WindowsAutopilotIntune

Connect-MSGraph

Type the Azure AD admin credentials.

Get-Autopilotprofile | ConvertTo-AutopilotconfigurationJSON

Copy detail into a JSON file, something like below:

{
"CloudAssignedDomainJoinMethod": 0,
"CloudAssignedDeviceName": "SN-%SERIAL%",
"CloudAssignedAutopilotUpdateTimeout": 1800000,
"CloudAssignedForcedEnrollment": 1,
"Version": 2049,
"CloudAssignedTenantId": "348841ce-b851-46d7-a6b2-xxxxxxxxx",
"CloudAssignedAutopilotUpdateDisabled": 1,
"ZtdCorrelationId": "c3808525-5be9-4eee-9e85-xxxxxxxxxx",
"Comment_File": "Profile OOBE",
"CloudAssignedAadServerData": "{\"ZeroTouchConfig\":{\"CloudAssignedTenantUpn\":\"\",\"ForcedEnrollment\":1,\"CloudAssignedTenantDomain\":\"curriccom.onmicrosoft.com\"}}",
"CloudAssignedOobeConfig": 1308,
"CloudAssignedTenantDomain": "curriccom.onmicrosoft.com",
"CloudAssignedLanguage": "en-AU"
}

Then you can copy the content of the Autopilot profile to notepad and save as AutopilotConfigurationFile.json, then save it ANSI to the MDTDeploymentShare\Scripts on the MDT server.

Create a step “Run Command Line” with name “Apply Autopilot Profile” after the step Install Operating System:

xcopy %SCRIPTROOT%\AutopilotConfigurationFile.json %OSDisk%\Windows\Provisioning\Autopilot\ /c

Create a step “Run Command Line” with name “Delete Unattend.xml” , so that Windows will start up in OOBE instead of continue to be deployed with the MDT Task Sequence.

cmd.exe /c del %OSDisk%\Windows\Panther\unattend.xml /s

Setup Complete:

create a folder Autopilot_default under MDTDeploymentShare\Scripts.

Create a cmd file:

@echo off
:: // ***************************************************************************
:: //
:: //
:: // File: SetupComplete.cmd
:: //
:: // Version: 1.0
:: //
:: // Purpose: Cleanup after MDT Autopilot deployment
:: //
:: // ***************************************************************************

:: Workaround for incorrectly-registered TS environment
reg delete HKCR\Microsoft.SMS.TSEnvironment /f > nul 2>&1
rmdir /Q /S c:\MININT 
rmdir /Q /S c:\_SMSTaskSequence
del /Q c:\LTIBootstrap.vbs

Save as SetupComplete.cmd to the folder Autopilot_default

In the PostInstall before the Restart computer, crate a step “Run Command Line” with name “Setup Complete”command line value is :

xcopy %SCRIPTROOT%\Autopilot_default\SetupComplete.cmd %OSDisk%\Windows\Setup\Scripts\ /c