Jump to content

Script to rename computer by serial number and force restart


Recommended Posts

Posted

Are you looking to rename a computer to its serial number or cross reference a list that associates a name based on a serial number.

Can you give an example

Posted
I would like to rename for example a Hp laptop with its serial number that is usually on the bottom of the laptop, but want to automate the process and cut out mistakes
Posted
Well "Wmic bios get serial number" produces the serial number and that out put could be piped into another command. Or some kind of MDT/sccm task could do it.
Posted

I havnt tested it but something like this:

 

$PC = Get-WmiObject win32_bios | select serialnumber
Rename-Computer -NewName $PC -Restart -DomainCredential domain\adminaccount

Posted

Isn't there a risk that if you have different manufacturers on your network that they may use the same serial numbers - creating 2 machines with the same name?

 

I thought Mac address was the only truly unique "serial"?

Posted (edited)

This script works on mine.

In theory regardless of the script used, if there is a computer name that is the same on the network it should error like it does if you manually change it through the GUI.

 

if you are going to run this within a domain admin account then it will authenticate ok however if you automate it under a user that doesn't have permission then you may have to supply the switch -User and -Password. bear in mind this will be readable whilst the script runs.

 

ChangeName.cmd

  @echo off
for /f "tokens=*" %%f in ('wmic bios get serialnumber /value ^| find "="') do set "%%f"
Echo My Serial Number is %serialnumber%
Set NewPCName=%SerialNumber%

for /f "tokens=*" %%f in ('wmic computersystem get name /value ^| find "="') do set "%%f"
Set OLDPCName=%Name%
Echo %NEWPCNAME%
Echo %OLDPCNAME%

if %NEWPCNAME% == %OLDPCNAME% (
GOTO END
) ELSE (
GOTO DEPOL
)

:DEPOL

echo This computer will be renamed from %OLDPCNAME% to %NEWPCNAME%
wmic computersystem where caption='%OLDPCNAME%' rename %NEWPCNAME%
echo This computer is scheduled to restart in 60 seconds
shutdown -r -t 60
timeout 55

:END
echo end


tested on a windows 7 computer

Edited by dapaulio
Posted
Isn't there a risk that if you have different manufacturers on your network that they may use the same serial numbers - creating 2 machines with the same name?

 

I thought Mac address was the only truly unique "serial"?

 

Personally I wouldn't use the Serial as a computer name mainly for the reason of remote supporting the computer, that doesn't mean that your reason for using it aren't justified or wrong

 

WDS uses a combination of string prefix and MAC address

Posted
I put together a powershell script which will do this. I created it to set up a new machine. I can send this to you later if you like

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...