Forum Discussion
Automatically configure Windows Autopilot device names using a CSV File
Many thanks for your reply.
I will test out your script over the next few days.
- 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."
}- UpNorthIntuneNov 04, 2024Iron Contributor
Happy for a PowerShell script that pop's up and ask's you to enter the asset details.
What ever the easiest solution is.
- Nov 04, 2024It should be done automatically without user intervention, running it as an Intune script as System should work. Could you add Start-Transcript c:\windows\temp\rename.txt at the top and stop-Transcript at the end and add it to Intune again? That should create a c:\windows\temp\rename.txt log file, which will tell you more.
- UpNorthIntuneNov 04, 2024Iron ContributorHi Harm
Sorry for the delay in replying, I have been flat out with other projects.
I have tried several scripts without success, I will be looking into working on this problem this week.
I will keep you posted.
Thanks