question

Nowtside-5323 avatar image
0 Votes"
Nowtside-5323 asked AllenLiu-MSFT commented

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.

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.

windows-server-powershellmem-mdt
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AllenLiu-MSFT avatar image
0 Votes"
AllenLiu-MSFT answered AllenLiu-MSFT commented

Hi, @Nowtside-5323
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.



1.jpg (78.7 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It seems there is no update for a couple of days. May we know the current status of the problem? Is there any other assistance we can provide?

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

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--

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.