none
Renaming Computers by Referencing Serial Number RRS feed

  • General discussion

  • I created this script to rename computers by referencing two external files with serial numbers and new names but it's not working, I'm getting incorrect syntax errors. My IDE isn't picking up any issues though. Any ideas on debugging? Thanks in advance!


    @echo off

    SET i=0
    FOR /F %%a IN (serial.txt) DO (
       SET serial[!i!]=%%a
       SET /A i+=1)

    SET i=0
    FOR /F %%a IN (name.txt) DO (
       SET name[!i!]=%%a
       SET /A i+=1)

    FOR /f "tokens=*" %%f IN ('wmic bios get serialnumber /value ^| find "="') DO SET "%%f"

    FOR /f "tokens=*" %%f IN ('wmic computersystem get oldname /value ^| find "="') DO SET "%%f"

    FOR /L %%g IN (0,1,157) DO
    (
      if %serial[%%g]%==%serialnumber% 
      (
        SET newname=name[%%g]
        wmic computersystem where caption='%oldname%' rename %newname%
      )
    )
    • Changed type Bill_Stewart Thursday, December 20, 2018 9:19 PM
    • Moved by Bill_Stewart Thursday, December 20, 2018 9:19 PM This is not "debug/fix/rewrite my script for me" forum
    Friday, October 19, 2018 8:25 PM

All replies

  • Don't use batch. Use PowerShell instead.


    -- Bill Stewart [Bill_Stewart]

    Friday, October 19, 2018 8:32 PM
  • This does not rename a computer in AD.  It just changes the local computer name.

    Without an exact error message it is not possible to help.

    As Bill has noted - use PowerShell.


    \_(ツ)_/

    Friday, October 19, 2018 8:47 PM