powershell to automatically get the computer SerialNumber and then rename the computer

陈帅 141 Reputation points
2021-06-25T05:13:29.39+00:00

Use powershell to automatically get the computer SerialNumber and then rename the computer, for example: BJ-SerialNumber, but report the error, please help correct the error, the correct script. Thank you

SerialNumber=Get-WmiObject -class win32_bios | Select-Object SerialNumber
$computer=BJ-%SerialNumber%
Rename-Computer -NewName $computer

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-06-25T07:24:33.713+00:00

    Hi,

    Please run the below script as administrator.

    $SerialNumber = (Get-WmiObject -class win32_bios).SerialNumber  
    $computer = "BJ-$SerialNumber"  
    Rename-Computer -NewName $computer -Force  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer 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.

    6 people found this answer helpful.

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.