Want to rename computer after or during Autopilot

Bonus12 1,126 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?

Microsoft Security | Windows Autopilot
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Windows for business | Windows Client for IT Pros | User experience | Other
Microsoft Security | Intune | Other
{count} votes

Accepted answer
  1. Limitless Technology 44,766 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. Rich Matheisen 47,901 Reputation points
    2023-04-25T18:53:31.0033333+00:00
    0 comments No comments

  2. Simon Ren-MSFT 40,341 Reputation points Microsoft External Staff
    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

  3. Pavel yannara Mirochnitchenko 13,336 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


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.