Hi,
To automatically change the device name when applying an OS through SCCM (System Center Configuration Manager) and have the number increase for each new device, you can use the following steps:
Automate Computer Name during OSD in ConfigMgr 2012 with PowerShell
Replace OSDComputerName.ps1
# Define the base name and initial number
$BaseName = "ABA-Laptop-"
$InitialNumber = 1
# Get the current number from a shared file to continue incrementing
$NumberFilePath = "\\share\OSDeployment\DeviceNumber.txt"
if (Test-Path -Path $NumberFilePath) {
$CurrentNumber = Get-Content $NumberFilePath
} else {
$CurrentNumber = $InitialNumber
}
# Generate the new device name
$NewDeviceName = $BaseName + "{0:D2}" -f $CurrentNumber
# Increment the number for the next device
$NextNumber = $CurrentNumber + 1
# Save the next number to the shared file for future use
$NextNumber | Out-File -FilePath $NumberFilePath
$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$TSEnv.Value("OSDComputerName") = $NewDeviceName