Want to rename computer after or during Autopilot

Bonus12 1,116 Reputation points
2023-04-25T14:30:30.4+00:00

Hi, Trying to add part of the serial number to the computer name but because Autopilot Hybrid mode doesn't allow that so I'm trying to modify the computer name after provisioning. I'm using Rename-Computer PS cmdlet, but doesn't work when I push the script from intune and I get an error says access denied. Thoughts on how to rename a computer after it is already joined the domain from Intune?

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,967 questions
Windows Autopilot
Windows Autopilot
A collection of Microsoft technologies used to set up and pre-configure new devices and to reset, repurpose, and recover devices.
426 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
4,604 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,238 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,194 questions
{count} votes

Accepted answer
  1. Limitless Technology 44,081 Reputation points
    2023-04-26T12:27:06.3066667+00:00

    Hi, I'd be happy to help you out with your question. Sorry for the inconvenience caused. It's possible that you're encountering a permissions issue when running the command from Intune. To resolve this, you may need to ensure that the account running the Rename-Computer command has the necessary permissions to rename the computer. You can do this by adding the account to the local administrators group on the target computer. Another option is to run the script locally on the target computer instead of pushing it from Intune. This can help ensure that any permission issues are resolved before attempting to run the script remotely. If you need to run the script from Intune, you can try wrapping the Rename-Computer command in a PowerShell script that elevates the execution level to administrator using the Start-Process cmdlet with the -Verb RunAs option. However, it's important to remember that renaming a computer after it has been provisioned can cause issues with applications and services that rely on the computer name. So be sure to thoroughly test any changes before deploying them to production. If you're still having trouble renaming the computer, there are third-party tools and scripts available that can help. For example, you might try the Rename-Computer tool from Sysinternals or the PowerShell script available on the Microsoft TechNet Gallery. Here's an example PowerShell script that renames the computer based on the serial number: $serialNumber = (Get-WmiObject Win32_BIOS).SerialNumber $computerName = "MyComputer-$serialNumber" Rename-Computer -NewName $computerName -Force -Restart This script gets the serial number of the computer using the Get-WmiObject cmdlet and then appends it to the desired computer name. It then uses the Rename-Computer cmdlet to rename the computer and restart it. Note that the -Force parameter is used to suppress confirmation prompts, and the -Restart parameter is used to restart the computer after renaming it. If you have any other questions or need assistance with anything, please don't hesitate to let me know. I'm here to help.

    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.


3 additional answers

Sort by: Most helpful
  1. Simon Ren-MSFT 31,601 Reputation points Microsoft Vendor
    2023-04-26T08:05:41.2366667+00:00

    Hi,

    Thank you for posting in Microsoft Q&A forum.

    We can refer to below articles to rename computer via Intune:

    Renaming Windows Devices in Intune

    Bulk rename devices

    How to rename Windows 10 devices in Intune using PowerShell

    Thanks for your time. Have a nice day!

    Best regards,
    Simon


    If the response is helpful, please click "Accept Answer" and upvote it. Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Pavel yannara Mirochnitchenko 12,381 Reputation points MVP
    2023-04-26T08:47:27.4433333+00:00

    Here you go :) ..change something to your prefix. To be more effective, I suggest to wrap ps1 to win32 app.

    #Rename hostname based on prefix set and serial $Prefix = 'SOMETHING' $Serial = Get-WMIObject -Class "Win32_BIOS" | Select -Expand SerialNumber $NewComputername = $Prefix + $Serial Write-Output $NewComputername Rename-Computer -NewName $NewComputername -Force