Utilizing Postscripts (Rename, JoinDomain, Drivers, Snapins)


  • Senior Developer

    [quote=“Corneliu Mahu, post: 40382, member: 27456”]Hi Lee,
    Can I add in this way the unattend.xml file to the postscripts? If yes, how?
    Thanks

    Corneliu[/quote]

    You can use these postscripts to alter your unattend file directly.

    What you need to do is know what line needs to be changed to what and make the post scripts mount the partition containing the unattend file and make the adjustments as needed.



  • Hi Lee,
    Can I add in this way the unattend.xml file to the postscripts? If yes, how?
    Thanks

    Corneliu


  • Developer

    potentially this means for rename, ad, snapins you wouldn’t need to use fog client… although fog client would be there as a backup if anything failed and i would always recommend still utilizing the FOG Client especially the new one when it comes out, you’d be silly not to!!!


  • Developer

    now this is completely up to you, whatever you want it to do … i use it so that it downloads needed data for unique snapins and i also use it to get switch from fog so that i’m only actually using one script for all our “builds” and the script knows what’s needed by that switch. that way i only ever have to maintain one “snapin”

    i.e. snapin 1 = myscirpt.exe with a switch of /DefaultBuild in my script catches switch so if /DefaultBuild set $somevariable to true then
    if $somevariable = true then
    install these pieces software, add these shortcuts etc etc etc

    a one snapin rules all type scenario :)

    [CODE]#!/bin/sh

    snpchk=wget -O - --post-data="mac=${mac}" "http://${web}service/snapcheck.php" 2>/dev/null #checks for snapintask
    if [ “$snpchk” == “1” ]; then
    setupcmd="/ntfs/Windows/Setup/Scripts/SetupComplete.cmd";
    mkdir /ntfs/Windows/Setup/Scripts
    #this line below pulls my latest build script from server
    cp /fog/CompleteBuild/CompleteBuild.exe /ntfs/Windows/Setup/Scripts/CompleteBuild.exe &>/dev/null
    #copies lastest setupcomplete.cmd from server
    #which only actually contains one line to execute
    #C:\Windows\Setup\Scripts\CompleteBuild.exe
    cp /fog/CompleteBuild/SetupComplete.cmd $setupcmd #above script
    sloc="/ntfs/Windows/Setup/Scripts/Node.txt"; # this is just so my above script
    #knows which node to use to run software from (if needed) left in to give you
    #guys ideas…
    echo “$storageip” >> “$sloc”; # writes node ip to the text file
    #next line gets snapin name
    snapname=wget -O - --post-data="mac=${mac}&getSnapnames=1" "http://${web}service/snapcheck.php" 2>/dev/null
    #next gets snapin argument/switch
    snaparg=wget -O - --post-data="mac=${mac}&getSnapargs=1" "http://${web}service/snapcheck.php" 2>/dev/null
    #this next line adds the switch to the setupcomplete.cmd
    # so if switch was /DefaultBuild .cmd line would now look like:
    #C:\Windows\Setup\Scripts\CompleteBuild.exe /DefaultBuild
    #if switch empty just nothing gets added
    sed -i -e “s|$| ${snaparg}|g” $setupcmd

    #this is self explanatory - some of our builds rely on 24GB of map files
    #rather than adding them to the "general" image
    #as it's the select few machines
    #i get fog to add it for me after imaging
    #so if they ever change, just update on server, job done.
    if [ "$snapname" == "MAP Build" -o "$snapname" == "Example Build" -o "$snapname" == "Test Build" ]; then
        dots "Downloading Map Files";
        echo "In Progress";
        rsync -a --info=progress2 "/fog/SnapinData/Map Files" /ntfs
        echo " * Downloading Map Files Completed.";
    fi
    

    else
    echo “No Snapin Task Found - Snapin Setup Skipped”;
    fi[/CODE]


  • Developer

    this will remove the 2 needed reboots to rename and join domain (if hostname early is not used)

    not much info needed on this pretty self explanatory, uses sed to manipulate unattend.xml to be unique to that machine setting the name and ad details.

    only prereq is that your unattend.xml MUST include:
    <JoinWorkgroup>Workgroup</JoinWorkgroup>
    <Credentials>
    <Password></Password>
    <Username></Username>
    </Credentials>
    <JoinDomain></JoinDomain>
    <MachineObjectOU></MachineObjectOU>

    and other prereq is your ad username should be the new way of just username rather than old domain\username

    nice thing also, it’s not static info and uses fog variables for name and ad details

    one more thing to add, if machine is not set to join ad in fog, it will not add ad details to unattend :)

    fog.ad
    [CODE]#!/bin/sh

    hostadpwd=“PasswordtojoinAD”; #only downside to this method- this is the plain ad password
    unattend="/ntfs/Windows/Panther/unattend.xml";
    if [ -f “$unattend” ]; then
    dots “Preparing Sysprep File”;
    rm -f /ntfs/Windows/System32/sysprep/unattend.xml;
    echo “Done”;
    dots “Writing Computer Name”;
    sed -i “/ComputerName/s/*/$hostname/g” $unattend
    echo “Done”;
    dots “ComputerName Set To”;
    echo $hostname
    dots “Set PC To Join The Domain”;
    if [ “$addomain” != “” ]; then
    sed -i “/<JoinWorkgroup>/d” $unattend
    sed -i -e “s|<Password></Password>|<Password>${hostadpwd}</Password>|g”
    -e “s|<Username></Username>|<Username>${addomain}\\${aduser}</Username>|g”
    -e “s|<MachineObjectOU></MachineObjectOU>|<MachineObjectOU>${adou}</MachineObjectOU>|g”
    -e “s|<JoinDomain></JoinDomain>|<JoinDomain>${addomain}</JoinDomain>|g” $unattend
    echo “Done”;
    else
    echo “Skipped”;
    fi
    fi[/CODE]


  • Developer

    Always remove notation and you’ll see just how minimal lines of code it is :)
    fog.drivers
    [CODE]#!/bin/sh

    ceol=tput el;
    machine=dmidecode -s system-product-name; # Gets machine model
    machine="${machine%"${machine##*[![:space:]]}"}" #Removes Trailing Space
    system64="/ntfs/Windows/SysWOW64/regedit.exe"; # dirty way to determine if it’s 64bit or not
    if [ -f “$system64” ]; then
    setarch=“x64”
    else
    setarch=“x86”
    fi
    #############################################
    #this is not section necessary needed, it’s just to make the path “human readable”
    #rather than using osid for filepath
    if [ $osid == “5” ]; then
    osn=“Win7”
    elif [ $osid == “6” ]; then
    osn=“Win8”
    elif [ $osid == “7” ]; then
    osn=“Win8.1”
    fi
    #############################################
    dots “Preparing Drivers”;

    below creates local folder on imaged pc

    #this can be anywhere you want just remember
    #to make sure it matches throughout!
    mkdir /ntfs/Windows/DRV &>/dev/null;
    echo -n “In Progress”;

    #there’s 3 ways you could handle this,
    #driver cab file, extracted driver files or both
    #so on the server put extracted driver files to match below folder tree
    #i.e. Model Latitude E5410, Windows 7 x86 image would be:
    #/fog/Drivers/Win7/Latitude E5410/x86
    rsync -aqz “/fog/Drivers/$osn/${machine}/$setarch” /ntfs/Windows/DRV &>/dev/null;

    #if you wanted to use driver.cab use this line below.
    #i.e. /fog/Drivers/Win7/Latitude E5410/E5410-Win7-A07-KTT4G.CAB
    cabextract -d /ntfs/Windows/DRV “/fog/Drivers/$osn/${machine}”/*.CAB &>/dev/null;

    #if you wanted to mix both cab and extracted use these:
    rsync -aqz --exclude=’.CAB’ “/fog/Drivers/$osn/${machine}/$setarch” /ntfs/Windows/DRV &>/dev/null;
    cabextract -d /ntfs/Windows/DRV “/fog/Drivers/$osn/${machine}”/
    .CAB &>/dev/null;

    #this next bit adds driver location on pc to devicepath in registry (so sysprep uses it to reference)

    remember to make devicepath= match the path you’ve used locally

    #also do not remove %SystemRoot%\inf
    #and to add more locations just use ; in between each location
    regfile="/ntfs/Windows/System32/config/SOFTWARE"
    key="\Microsoft\Windows\CurrentVersion\DevicePath"
    devpath="%SystemRoot%\inf;%SystemRoot%\DRV";
    reged -e “$regfile” &>/dev/null <<EOFREG
    ed $key
    $devpath
    q
    y
    EOFREG
    echo -e “\b\b\b\b\b\b\b\b\b\b\b${ceol}Done”; # this just removes “In Progress and replaces it with done :-)”[/CODE]


Log in to reply
 

470
Online

6.1k
Users

13.5k
Topics

127.4k
Posts