How do i set a computers name to be the same as the last 4 letters in the disk drives serialnumber? The solution needs to be automatic with MDT. So either a rule in customsettings.ini or a powershell command would worke best.

Nowtside 1 Reputation point
2021-09-10T11:24:15.667+00:00

My previous solution to this was to use the rule "OSDComputerName=-%SerialNumber%". However this rule changes the name based on the serialnumber on the motherboard while i need it to be changed based on the serialnumber on the hard drive.

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).
831 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. AllenLiu-MSFT 40,551 Reputation points Microsoft Vendor
    2021-09-13T06:20:07.07+00:00

    Hi, @Nowtside
    Thank you for posting in Microsoft Q&A forum.

    The pre-defined variables %SerialNumber% in MDT is bios serial number, not hard drive serial number.
    We may try to customize a script to rename the computer name like below picture, we can use "wmic diskdrive get serialnumber" to get the hard drive serial number, and use substring to get the last 4 letters.
    131486-1.jpg
    For more details, please refer to the last picture in below link:
    https://c-nergy.be/blog/?p=3933

    And how to use the script in task sequence, please to below link and search the paragraph "Configure a task sequence to run PowerShell Script":
    https://c-nergy.be/blog/?p=3964
    (Please note: Information posted in the given link is hosted by a third party. Microsoft does not guarantee the accuracy and effectiveness of information.)


    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.


  2. Limitless Technology 39,376 Reputation points
    2021-09-13T09:27:28.743+00:00

    Hi ,

    Thank you for posting the query on Microsoft Community.

    I understand your concern and will assist you to resolve this issue. You can the below powershell commands for renaming the computer as per your requirement.

    $serial = Get-PhysicalDisk | Select-Object SerialNumber
    $newname = $Serial.Substring(3,5)
    Rename-Computer -NewName $newname -Force -Restart

    Note: I took number from 3 to 5 in my example. In case if you have 15 or more than numbers, you can run , you can modify the commands as per your requirement. In below example i have 15 and took numbers from 11 to 15.

    $newname = $Serial.Substring(11,15)

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    0 comments No comments