MDT to Autopilot not setting PC name

Scott 6 Reputation points
2022-08-21T00:05:38.823+00:00

We are deploying an MDT image that triggers Autopilot after the OS is laid down (by copying the autopilot JSON file) using this technique:
how-to-deploy-autopilot-device-fast-with-mdt

This seems to work but the PC name I am setting in MDT is not being set on the PC. This seems to be because the Unattend file is being deleted to allow Autopilot to run at the first reboot. I verified this by not deleting the Unattend and it sets the name fine so everything is setup on that side (but of course does not let Autopilot take over).
I will admit, I don't know a lot about how all of that works so I figured I would ask. This seems to make sense but we need a way to be able to use the naming logic we have setup in MDT to name the PC before its joined to AAD.
Thanks for any tips or help you can give,
Scott

Microsoft Deployment Toolkit
Microsoft Deployment Toolkit
A collection of Microsoft tools and documentation for automating desktop and server deployment. Previously known as Microsoft Solution Accelerator for Business Desktop Deployment (BDD).
855 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Scott 6 Reputation points
    2022-08-22T17:10:49.3+00:00

    I found this while searching and was able to tweak it for my needs. Its works so I figured I would share in case anyone finds this while searching...LOL
    This is a Powershell script that gets run right after the Install Operating System TS:

    $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment  
      
    #Get Name and OS Disk from MDT  
    $MDTComputerName = $TSEnv.Value("OSDComputerName")  
    $MDTOSDisk = $TSEnv.Value("OSDisk")  
      
    # Read the current config  
    $config = Get-Content .\AutoPilotConfigurationFile.json | ConvertFrom-Json  
      
    # Add the computer name  
    $config | Add-Member "CloudAssignedDeviceName" $MDTComputerName  
      
    # Write the updated file  
    $targetDrive = $tsenv.Value("OSDisk")  
    $null = MkDir "$targetDrive\Windows\Provisioning\Autopilot" -Force  
    $destConfig = "$targetDrive\Windows\Provisioning\Autopilot\AutoPilotConfigurationFile.json"  
    $config | ConvertTo-JSON | Set-Content -Path $destConfig -Force  
    

    It will get the PCname set in MDT and insert it into the JSON file I exported for Autopilot. Seems to work very well so far.

    Thanks,
    Scott

    1 person found this answer helpful.

  2. Simon Ren-MSFT 32,146 Reputation points Microsoft Vendor
    2022-08-23T09:10:40.633+00:00

    Hi Scott,

    Thanks very much for your feedback. We're glad that it's working ok now. It's appreciated that you could click "Accept Answer" to the helpful reply, this will help other users to search for useful information more quickly. Here's a short summary for the problem.

    Problem/Symptom:
    Want to use the naming logic setup in MDT to set PC name in MDT OS deployment before the device joins to AAD.

    Solution/Workaround:
    Using below PowerShell script that gets run right after the Install Operating System TS to fulfill the need.

     $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment  
          
     #Get Name and OS Disk from MDT  
     $MDTComputerName = $TSEnv.Value("OSDComputerName")  
     $MDTOSDisk = $TSEnv.Value("OSDisk")  
          
     # Read the current config  
     $config = Get-Content .\AutoPilotConfigurationFile.json | ConvertFrom-Json  
          
     # Add the computer name  
     $config | Add-Member "CloudAssignedDeviceName" $MDTComputerName  
          
     # Write the updated file  
     $targetDrive = $tsenv.Value("OSDisk")  
     $null = MkDir "$targetDrive\Windows\Provisioning\Autopilot" -Force  
     $destConfig = "$targetDrive\Windows\Provisioning\Autopilot\AutoPilotConfigurationFile.json"  
     $config | ConvertTo-JSON | Set-Content -Path $destConfig -Force  
    

    Thanks again for your time! Have a nice day!

    Best regards,
    Simon


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  3. Simon Ren-MSFT 32,146 Reputation points Microsoft Vendor
    2022-08-22T07:12:07.167+00:00

    Hi,

    Thanks for posting in Microsoft Q&A forum.

    We could try to use the variable OSDComputername to set computer name during the deployment process. Similar thread here:
    MDT 2012 PART VIII – Automatically Set computer Name
    Note: This is non-Microsoft link, just for your reference.

    Hope it helps. Thanks for your time.

    Best regards,
    Simon


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  4. Scott 6 Reputation points
    2022-08-22T11:35:33.187+00:00

    Thanks for the response. This is how I have my MDT setup but I think by deleting the Unattend file so Autopilot can take over causes the rename not to happen. I think I need a different way to transfer the name.

    Thank,
    Scott

    0 comments No comments