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!

PENDING Rename Computer Name As Serial Number During OSD

sathishk179

New Member
Messages
1
Reaction score
0
Points
1
I am trying to rename the computer using the script below, but when I use the task sequence to rename the computer, it is not working. Kindly help, as I am new to SCCM.


$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

1739539652505.png
 
Back
Top