Forum Discussion
Automatically configure Windows Autopilot device names using a CSV File
I've used the Asset Tag in the bios to rename the computer to that. If you sticker the device, you could also set that same name in the bios if you have an Asset Tag option. Then you add a script to Intune which does something like this where if the computer name doesn't match a specific name, then it will be renamed without rebooting it and the computer name will become the Asset Tag name from the Bios setting after the next reboot.
if ($env:COMPUTERNAME -notmatch 'XYZ') {
if (((Get-WmiObject win32_SystemEnclosure).smbiosassettag -ne $env:COMPUTERNAME)) {
Rename-Computer -NewName ((Get-WmiObject win32_SystemEnclosure).smbiosassettag)
}
}
- UpNorthIntuneAug 28, 2024Iron ContributorHi Harm
Many thanks for your reply.
I will test out your script over the next few days.- Nov 03, 2024Did this answer your question?
- UpNorthIntuneNov 04, 2024Iron Contributor
This is the script I am running, but it's not working correctly
Any idea's?
I am no powershell guru.# Ensure script is running with administrator privileges
if (-not ([System.Security.Principal.WindowsIdentity]::GetCurrent().Groups -match "S-1-5-32-544")) {
Write-Host "This script requires administrator privileges. Please run as administrator."
exit
}# Check if required PowerShell version is met (version 3.0 and above recommended)
if ($PSVersionTable.PSVersion.Major -lt 3) {
Write-Host "This script requires PowerShell version 3.0 or higher."
exit
}# Load computer name and SMBIOS asset tag information
$computerName = $env:COMPUTERNAME
$assetTag = (Get-WmiObject win32_SystemEnclosure).smbiosassettag# Ensure that asset tag is not empty or null to avoid renaming issues
if ([string]::IsNullOrEmpty($assetTag)) {
Write-Host "Asset tag is empty or not available. Cannot proceed with renaming."
exit
}# Check if computer name does not contain 'abc' and if it differs from the asset tag
if ($computerName -notmatch 'abc') {
if ($assetTag -ne $computerName) {
try {
# Rename computer to match the SMBIOS asset tag
Rename-Computer -NewName $assetTag -Force -ErrorAction Stop
Write-Host "Computer renamed successfully to '$assetTag'. Please restart to apply changes."
}
catch {
Write-Host "Error renaming computer: $($_.Exception.Message)"
}
}
else {
Write-Host "Computer name already matches the SMBIOS asset tag. No renaming required."
}
}
else {
Write-Host "Computer name contains 'abc'. No renaming required."
}
- Sep 08, 2024Any update?
- UpNorthIntuneNov 25, 2024Iron Contributor
Hi Harm,
Sorry for the delay , other projects took priority.
Still having no success with the script.
Have spent a few hours this morning trying different methods but still no joy.The HP laptop I am using is a HP ProBook 640 G5 and the BIOS refers to the asset settings as System IDs
Asset Tracking Number
andOwnership Tag
The scripts I have tried seem unable to reference this data in the BIOS.
Any help is appreciated or another solution.Thanks