Create a .vbs file called getcomputername.vbs or something like that. Add these commands to the file:
set env = CreateObject("Microsoft.SMS.TSEnvironment")
Name = inputbox("Enter the name for the new computer" ,"Prompt for Computer Name:",env("_SMSTSMachineName"),400,0)
env("OSDComputerName") = Name
Create an SCCM package and point the package source to the source folder that you stored the .vbs file in. You don’t need to create a program item, just the package. Add it to the DPs.
Edit your OSD task sequence and add a task to “Run Command Line”. For the name use something like “Get Computer Name”. For the command line use “cscript.exe getcomputername.vbs” (get rid of the quotes). Select the Package option and choose the package you built in the previous step.
I added my Get Computer Name task sequence after the Partition Disk 0 task but I’m not sure it matters.
Advertise the task sequence