Join Domain/Customize Computer Name without Host Registration



  • Just like the title says, is there a way to customize the computer name and join a domain without registering the pc? Maybe just a dialog box at the beginning and an automatic domain join at the end? Registering is pointless for us because we only image new laptops that we purchase. We don’t have anything to do with the machines when they come back. So going through the registering process is pointless.



  • @george1421 Oh, my apologies. Thank you very much for your help. You’re truly a wizard as your profile picture shows. ;) Thank you again!


  • Moderator

    @ConJon Yes that is already part of the scripts at the link provided in a previous post below. I’ll link it again here: https://forums.fogproject.org/topic/11126/using-fog-postinstall-scripts-for-windows-driver-injection-2017-ed

    Its covered in the fog.updateunattend script section. You will probably want to remove the non-value added parts of that script like connecting to AD and such.



  • @george1421 Is it possible to combine this with the driver injection, as having driver injection is still a good idea to have in my opinion.



  • @george1421 Thank you very much! Sorry for the late reply. It’s been very busy lately. We have been swapping out switches and equipment and Access Points and Printers. Just been a hectic couple of weeks


  • Moderator

    I mashed up the two scripts to make this:

    #!/bin/bash
    . /usr/share/fog/lib/funcs.sh
    [[ -z $postdownpath ]] && postdownpath="/images/postdownloadscripts/"
    case $osid in
        5|6|7|9)
            clear
            [[ ! -d /ntfs ]] && mkdir -p /ntfs
            getHardDisk
            if [[ -z $hd ]]; then
                handleError "Could not find hdd to use"
            fi
            getPartitions $hd
            for part in $parts; do
                umount /ntfs >/dev/null 2>&1
                fsTypeSetting "$part"
                case $fstype in
                    ntfs)
                        dots "Testing partition $part"
                        ntfs-3g -o force,rw $part /ntfs
                        ntfsstatus="$?"
                        if [[ ! $ntfsstatus -eq 0 ]]; then
                            echo "Skipped"
                            continue
                        fi
                        if [[ ! -d /ntfs/windows && ! -d /ntfs/Windows && ! -d /ntfs/WINDOWS ]]; then
                            echo "Not found"
                            umount /ntfs >/dev/null 2>&1
                            continue
                        fi
                        echo "Success"
                        break
                        ;;
                    *)
                        echo " * Partition $part not NTFS filesystem"
                        ;;
                esac
            done
            if [[ ! $ntfsstatus -eq 0 ]]; then
                echo "Failed"
                debugPause
                handleError "Failed to mount $part ($0)\n    Args: $*"
            fi
            echo "Done"
            debugPause
            while [[ $res != "#!ok" ]]; do
                echo -n " * Enter hostname for this computer: "
                read host
                if [[ ${#host} -gt 15 ]]; then
                    host=${host:0:15}
                    echo " | Truncated to 15 characters: $host"
                    usleep 2000000
                fi
                host=$(echo $host | base64)
                res=$(curl -Lks --data "host=$host" ${web}service/hostnameloop.php 2>/dev/null)
                [[ $res != "#!ok" ]] && echo "$res"
            done
            unattends=$(find /ntfs/ -iname "unattend.xml")
            for unattend in $unattends
                [[ ! -f $unattend ]] && return
                dots "Writing Computer Name to $unattend"
                sed -i "/ComputerName/s/*/$host/g" $unattend >/dev/null 2>&1
                if [[ ! $? -eq 0 ]]; then
                    echo "Failed"
                    debugPause
                    handleError "Failed to update originating unattend file"
                fi
                echo "Done"
                echo "ComputerName set to $host in $unattend"
                debugPause
            done
            umount /ntfs
            ;;
        *)
            echo "Non-Windows Deployment"
            debugPause
            return
            ;;
    esac
    
    

    Will it work?? I put no effort into debugging it, but in theory the logic looks right.

    This file should be saved as fog.custominstall in /images/postinstallscripts. Its mode changed to 777 and the fog.postinstall script updated to call this fog.custominstall script as outlined in the tutorial.

    The only thing you need to ensure is that your unattend.xml file has the default host name set to star ( * ) which tells windows to pick a random name. This script will replace the star ( * ) with the name provided in the script. The deployment will pause at this point in the script until the IT admin enters a value is the only caveat I see.


  • Moderator

    If you look at the FOG Project github site, specifically this file: https://github.com/FOGProject/fos/blob/master/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.man.reg at line 160 https://github.com/FOGProject/fos/blob/master/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.man.reg#L160

    You will see where the full registration script asks the user for the computer’s host name.

    while [[ $res != "#!ok" ]]; do
        echo -n " * Enter hostname for this computer: "
        read host
        if [[ ${#host} -gt 15 ]]; then
            host=${host:0:15}
            echo " | Truncated to 15 characters: $host"
            usleep 2000000
        fi
        host=$(echo $host | base64)
        res=$(curl -Lks --data "host=$host" ${web}service/hostnameloop.php 2>/dev/null)
        [[ $res != "#!ok" ]] && echo "$res"
    done
    

    Now all you need is to glue the bits together.


  • Moderator

    @ConJon ok then probably your best route is to create a post install script. That script (bash shell script) runs after the image has been pushed to the target computer and before the target computer reboots leaving FOS.

    This post install script should ask for computer name. And then take the returned results, display it for the user to confirm, and then finally update the unattend.xml file with the computer name. This way when windows setup and OOBE runs it reads the host name from the unattend.xml file and renames the computer properly.

    The update unattend.xml part is not hard. I have a tutorial on post install scripts here: https://forums.fogproject.org/topic/11126/using-fog-postinstall-scripts-for-windows-driver-injection-2017-ed the script in question is fog.updateunattend.

    The code fragment that is important (outside of some setup code) is this:

    sed -i "/ComputerName/s/*/$hostname/g" $unattend >/dev/null 2>&1
    

    With that one command it will search the unattend file and replace </ComputerName>*</ComputerName> with </ComputerName>computername</ComputerName> or what ever is in the variable $hostname. That variable $hostname will come from the prompt to the IT admin.



  • @george1421 We name them in a numeric sequence. It’s (Name of Company)-115121, the next laptop is (Name of company)-115122, and the next one is (Name of Company)-115123, and so on so fourth.



  • This post is deleted!

  • Moderator

    What would you name the machines (give example)? Is it something that can be calculated?


Log in to reply
 

410
Online

5.9k
Users

13.2k
Topics

124.1k
Posts