SCCM – PowerShell, VBScript – Name Computer in Task Sequence

email me

This is how you automate the process of naming computers during OSD.

PowerShell Method

First, create an application package, but choose Do not create a program, instead of Standard for the program type.


$SerialNumber = (Get-WmiObject -Class Win32_BIOS | Select-Object SerialNumber).SerialNumber
$OSDComputerName = "ABC-" + $SerialNumber
$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
#$TSEnv.Value("$env:computername") = "$OSDComputerName"
$TSEnv.Value("OSDComputerName") = "$OSDComputerName"

#Rename-Computer -ComputerName "$env:computername" -NewName "$OSDComputerName"
#Rename-Computer -ComputerName "OSDComputerName" -NewName "$OSDComputerName"


Next, in the Task Sequence, create three Run Commands:

powershell.exe -noprofile -command “Set-ExecutionPolicy Bypass LocalMachine” -force

powershell.exe -noprofile -file OSDComputerName.ps1
* make sure you link an empty package (an application package with no program) to the OSDComputername.ps1

powershell.exe -noprofile -command “Set-ExecutionPolicy RemoteSigned LocalMachine” -force

* Note, this method does require that PowerShell be enabled in the boot.wim


VBScript Method

Make an item in Post Setup pointing to this script. Add a SCCM Restart.

on error resume next

Dim computername

strComputer = "."

Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)

For each objitem in colitems
'Wscript.echo "Dell Service Tag: " & objitem.serialnumber
computername = objitem.serialnumber


'returns machine model number only
Set objWMI = GetObject("winmgmts:")
Set colSettings = objWMI.ExecQuery("Select * from Win32_ComputerSystem")

For Each objComputer in colSettings
LaptopModel = Trim(objComputer.Model)

Select Case LaptopModel

Case "HP EliteBook 840 G3"
strModel = "8403"

Case "HP EliteBook 840 G2"
strModel = "8402"

Case "HP EliteBook 840 G1"
strModel = "8401"

Case "HP EliteBook Folio 9480m"
strModel = "9480"

Case "HP EliteBook Folio 9470m"
strModel = "9470"

Case "HP EliteBook Folio 9460m"
strModel = "9460"

Case "HP EliteBook 8470p"
strModel = "8470"

Case "HP EliteBook 8460p"
strModel = "8460"

Case "HP EliteBook 8450p"
strModel = "8450"

Case "HP EliteBook 8440p"
strModel = "8440"

Case "HP EliteBook 6930p"
strModel = "6930"

Case "HP EliteBook 2530p"
strModel = "2530"

Case "HP EliteBook 2540p"
strModel = "2540"

Case "HP Compaq dc7900 Small Form Factor"
strModel = "7900"

Case "HP Compaq 8000 Elite SFF PC"
strModel = "8000"

Case "HP Compaq 8200 Elite SFF PC"
strModel = "8200"

Case "OptiPlex 755"
strModel = "755"

Case "OptiPlex 745"
strModel = "745"

Case "Latitude D630"
strModel = "630"

Case "Latitude D620"
strModel = "620"

Case "Latitude D430"
strModel = "430"

End Select

'used for models not explicitly defined
if strModel = "" then
'msgbox "no model was detected"
myLength = Len(LaptopModel)

For i = 1 To myLength
If Asc(Mid(LaptopModel, i, 1)) <> 32 Then
If Asc(Mid(LaptopModel, i, 1)) >= 48 And Asc(Mid(LaptopModel, i, 1)) <= 57 Then
myNumber = myNumber & Mid(LaptopModel, i, 1)
End If
'msgbox("no numeric")
End If
strModel = myNumber
end if

'testing only
'msgbox strModel

'renames machine with model number - service tag
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

For Each objComputer in colComputers

err = objComputer.Rename(strModel & "-" & computername)






Command Line

netdom renamecomputer member / /userd:administrator



Rename-Computer -ComputerName “$env:computername” -NewName “NewComputerName”

Rename-Computer -ComputerName “OSDComputerName” -NewName “NewComputerName”

Remotely Rename

$TargetComp=Read-Host -Prompt “Enter the Name of the Computer you want to change the name of “
$computerName = GWMI Win32_ComputerSystem -computername $TargetComp -Authentication 6
Write-host “Current Computer Name is ” $computerName
$name = Read-Host -Prompt “Please Enter the ComputerName you want to use.”
Write-host “New Computer Name ” $Name
$Go=Read-Host -prompt “Proceed with computer name change? (Y / N)”
$Reboot=Read-host -Prompt “Do you want to restart the computer? (Y / N)”
restart-computer -computername $TargetComp