Renaming multiple computers on Fog



  • Hi,
    Recently our head office decided to change the PC naming convention and they have asked us to rename all our lab computers (around 500 computers in different groups). Can you please advise me whats the best way to accomplish this without spending a lot of time. We also need to rename these in AD. I have researched few scripts but is there anything you would advise which we can do to do this change smoothly?
    Many thanks


  • Moderator

    @gabbas If you were using the latest version of the new fog client, it will rename the object for you in active directory.



  • Hi, Thanks for the suggestions. I imported the list of computers as csv, renamed the host names and imported back to the relevant group. This restarted the PCs and renamed them. Run a script to unjoin from the domain, restarted and fog hostname service re-joined the PCs back to the AD. I believe there will be other ways to do this as well (maybe in less steps) but this one worked for me.
    Thanks Again


  • Moderator

    Well I just noodled up a possible solution if the name exchange is not a logical one or one that can be calculated.

    Will it work??
    Have I tested it, No!

    First in case something goes really wrong, lets make a backup of the hosts table.
    mysqldump -u root -p fog hosts > /tmp/host_table_backup.sql

    If we need it we can restore the db with this command
    mysql -u root -p fog < /tmp/host_table_backup.sql

    The following commands are what we should need in mysql.

    USE fog;
    
    CREATE TABLE NameExchange (
        OldName varchar(16),
        NewName varchar(16) 
    );
    
    
    LOAD DATA LOCAL INFILE  
        '/temp/host-matrix.csv'
        INTO TABLE NameExchange  
        FIELDS TERMINATED BY ',' 
        ENCLOSED BY '"'
        LINES TERMINATED BY '\n'
        (OldName,NewName);
    
    UPDATE hosts
    INNER JOIN NameExchange ON hosts.hostName = NameExchange.OldName
    SET hosts.hostName = NameExchange.NewName;
    
    DROP TABLE NameExchange;
    
    
    1. We tell the mysql command processor we are working with the fog database.

    2. We’ll create a temp table to hold our new/old name matrix.

    3. Then import your csv file.

    4. Then update hosts.hostName based on the match between hostName OldName

    5. Lastly we’ll drop the matrix table since its not needed anymore.


  • Moderator

    Maybe cause I’m an old dba, or just old. For 500 computers I might look at doing this directly in the database (with SQL). Is the name transition a logical one? Can you explain the name format exchange?


  • Senior Developer

    Or, and I’m just saying cause why not.

    Get a list of the hosts into a CSV based off the “list” element of api, and script the rename by sending and update to each host to be updated.

    Right now the API only supports editing based on the item’s ID, but you CAN script it using FOG’s API system now.


  • Moderator

    @gabbas I do not recommend editing in excel, it’s notorious for assigning field types incorrectly messing up your data.

    I think you do have to delete the hosts before uploading the file, yes, so best to have a backup of the host list somewhere.



  • @Quazz Should I download in excel, just edit the name cell, save it and import it back to fog? Do I need to delete the existing hosts? Sorry I have not done this before…))


  • Moderator

    Download host list, bulk edit with new format, upload host list? Seems easiest to me on FOG’s end anyway. I don’t really use AD so can’t help you there, but others here might.


Log in to reply
 

355
Online

39.3k
Users

11.0k
Topics

104.4k
Posts

Looks like your connection to FOG Project was lost, please wait while we try to reconnect.