Chrisbf1 Posted August 20, 2017 Posted August 20, 2017 I am after a script to rename a computer by its serial number and restart. Any help would b appreciated
dapaulio Posted August 20, 2017 Posted August 20, 2017 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
Chrisbf1 Posted August 20, 2017 Author Posted August 20, 2017 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
nicholab Posted August 20, 2017 Posted August 20, 2017 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.
RobD Posted August 21, 2017 Posted August 21, 2017 I havnt tested it but something like this: $PC = Get-WmiObject win32_bios | select serialnumber Rename-Computer -NewName $PC -Restart -DomainCredential domain\adminaccount
SamanthaD Posted August 21, 2017 Posted August 21, 2017 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"?
dapaulio Posted August 21, 2017 Posted August 21, 2017 (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 August 21, 2017 by dapaulio
dapaulio Posted August 21, 2017 Posted August 21, 2017 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
Seriun Posted August 22, 2017 Posted August 22, 2017 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now