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

$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
