How to Rename Hostname Using Autopilot in Intune...?

?? Overview

When managing devices with Intune and Autopilot, it's common to enforce a naming convention that includes the device’s serial number or other identifiers.

?? Your Requirement

You want to configure a hostname that:

? Uses the device serial number in the name.

? Adds a prefix (e.g., "A") to the serial number.

? Applies to both new and existing devices.


? Solution Options

1?? Use Autopilot Deployment Profile (For New Devices)

2?? Use a PowerShell Script via Intune (For Existing Devices)


?? Method 1: Configure Hostname in Autopilot (For New Devices)

If the device is new or being re-enrolled, you can define a naming convention in Autopilot.

1?? Create an Autopilot Deployment Profile

  1. Sign in to Intune Admin Center ?? https://endpoint.microsoft.com
  2. Go to:Devices > Windows > Windows Enrollment > Deployment Profiles.
  3. Click "+ Create profile"
  4. Select Profile Type: Windows Autopilot for User-Driven or Pre-Provisioned Deployment.
  5. Configure General Settings: Profile Name: "Autopilot Hostname Policy". Join Type: Azure AD Join or Hybrid Azure AD Join. User Account Type: Standard or Administrator.

2?? Apply Device Name Template

  1. Scroll down to "Apply device name template".
  2. Enter the naming convention:

A{{SerialNumber}}

This ensures all devices follow this format: Example: A1234567890

Click Next, assign it to a device group, and Save.

? Devices will be named automatically when they enroll via Autopilot.


?? Method 2: Rename Existing Devices Using PowerShell in Intune

For devices already deployed, Autopilot’s device name template won’t apply. Instead, use a PowerShell script to rename them.

1?? Create the PowerShell Script

  1. Open Notepad and copy the script below:

# Get the device serial number

$SerialNumber = (Get-WmiObject Win32_BIOS).SerialNumber

# Define new hostname with "A" prefix

$NewComputerName = "A$SerialNumber"

# Rename the computer

Rename-Computer -NewName $NewComputerName -Force

# Restart to apply changes

Restart-Computer -Force

Save it as Rename-Device.ps1.


2?? Deploy the Script via Intune

  1. Go to Intune Admin Center ?? https://endpoint.microsoft.com.
  2. Navigate to: Devices > Scripts > + Add.
  3. Select "Windows 10 and later".
  4. Upload the PowerShell script (Rename-Device.ps1).
  5. Configure settings: Run script using logged-on credentials? → NoEnforce script signature check? → NoRun script in 64-bit PowerShell? → Yes
  6. Assign the script to device groups.
  7. Click Create and Deploy.

? Devices will rename on next policy sync & reboot.




Would you like help with


要查看或添加评论,请登录

Atish B的更多文章