Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

SOLVED Setting computer name on OSD

  • Thread starter Thread starter rjm2884
  • Start date Start date
  • Replies Replies 4
  • Views Views 7K

rjm2884

New Member
Messages
4
Reaction score
0
Points
1
We want to automate setting the computer name through the OSD. Instead of getting a dialog box and having the tech add the computer we what to be able to use the serial number of the machine or the Mac address to by pass the 15 character computer name.
 
I am using PowerShell script to rename the computer from default to serial number from BIOS. In my task sequence the script run right before join domain task.

$tsenv = New-Object -ComObject Microsoft.SMS.TSEnvironment
$OldComputerName = $ENV:Computername
$SN = (gwmi win32_bios).SerialNumber
$SN = $SN.Replace(' ','')
# test serial number for empty string, set to static NOSERIAL if empty
if([string]::IsNullOrWhiteSpace($SN)){ $SN = 'NOSERIAL' }
$Serial = "$($SN)"[0..14] -join ""
$NewComputerName = $Serial
Rename-Computer -ComputerName $OldComputerName -NewName $NewComputerName -Force
 
I am using PowerShell script to rename the computer from default to serial number from BIOS. In my task sequence the script run right before join domain task.

$tsenv = New-Object -ComObject Microsoft.SMS.TSEnvironment
$OldComputerName = $ENV:Computername
$SN = (gwmi win32_bios).SerialNumber
$SN = $SN.Replace(' ','')
# test serial number for empty string, set to static NOSERIAL if empty
if([string]::IsNullOrWhiteSpace($SN)){ $SN = 'NOSERIAL' }
$Serial = "$($SN)"[0..14] -join ""
$NewComputerName = $Serial
Rename-Computer -ComputerName $OldComputerName -NewName $NewComputerName -Force
Does this work with reimaging computers too or just fresh baremetal builds? because if they already exist in SCCM/MECM and you reimage them wont they get given the same name as their MECM object?

also - could you edit this so that it has a prefix? e.g $newcomputername = ABC-$serial
 
Last edited:
Does this work with reimaging computers too or just fresh baremetal builds? because if they already exist in SCCM/MECM and you reimage them wont they get given the same name as their MECM object?

also - could you edit this so that it has a prefix? e.g $newcomputername = ABC-$serial
Your prefix have 4 characters. You need to trim the serial number to have max 11 characters, so the final computer name will not exceed the max 15 characters. ABC-12345678901 (4 char "ABC-" + 11 char " trimmed serial" = 15 max characters). I run in this with new Surface devices having 15 char serial.

$Serial = "$($SN)"[0..10] -join ""
$Prefix = "ABC-"
$NewComputerName = $Prefix+$Serial
 
Your prefix have 4 characters. You need to trim the serial number to have max 11 characters, so the final computer name will not exceed the max 15 characters. ABC-12345678901 (4 char "ABC-" + 11 char " trimmed serial" = 15 max characters). I run in this with new Surface devices having 15 char serial.

$Serial = "$($SN)"[0..10] -join ""
$Prefix = "ABC-"
$NewComputerName = $Prefix+$Serial
Thanks! makes sense.
 
Back
Top