Announcement

Collapse
No announcement yet.

Renaming a PC based on serial number

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Renaming a PC based on serial number

    I have the following script that will rename a PC with the serial # of the PC.

    Code:
    'Rename computer by serial # v1.0 November 2009
    dim Bios, BiosSerial, objFSO, objTextFile
    'Const ForReading = 1, ForWriting = 2, ForAppending = 8
    
    'get serial number
    for each Bios in GetObject("winmgmts:").InstancesOf ("win32_bios")
    BiosSerial = Bios.SerialNumber
    exit for
    next
    
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    Set colComputers = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
    
    For Each objComputer in colComputers
    err = objComputer.Rename(BiosSerial)
    Next
    
    'messagebox
    msgbox "Computername changed to " + BiosSerial + "...", yes
    My problem is, I would like to add the name "BAKER-" before the serial number. The PC name should look like "BAKER-KAX4547". The script works perfectly for renaming to a serial number. I have tried placing the text everywhere, and can't seem to get it to rename while adding "BAKER-" before the serial. Any ideas?

  • #2
    Re: Renaming a PC based on serial number

    Try this

    For Each objComputer in colComputers
    err = objComputer.Rename("BAKER-" + BiosSerial)
    Next

    Comment


    • #3
      Re: Renaming a PC based on serial number

      Ah, I was missing the quotes. Thanks!

      Comment


      • #4
        Re: Renaming a PC based on serial number

        No probs.

        Glad to have helped.

        Comment

        Working...
        X