Last modified 5 years ago Last modified on 05/05/09 12:28:42
The following code can be placed in your site/config.pl. It sets the computer name of the build from the hostname of the computer as it is set by your DHCP server and is tested with the Linux boot disk.
So for example, if I am using dhcpd under Linux as my dhcp server, and I have this in my /etc/dhcpd.conf configuration file:
host vm-build-test.mydomain.com { hardware ethernet 00:0C:23:6B:63:4F; fixed-address 192.168.14.223; }
Then when I boot the machine with this MAC, my DHCP server will assign it that address and the hostname vm-build-test.mydomain.com. Whether the client doing the DHCP request takes any notice of it depends on the client, but Unattended does when booted using the Linux boot disk. The script will set the hostname of the computer to the first part of the DNS name shown above (the bit before the first period (.)). You can then query the hostname and use it to set the computername, which unattended will then use in the answer file it creates. All this happens before Windows Setup starts.
Final notes:
I put the two sleep lines in so I would have a chance to see what was happening - feel free to take them out.
use warnings;
use strict;
use Sys::Hostname;
my $host = hostname;
my $default_computer_name = $u->{'UserData'}->{'ComputerName'};
print "Trying to determine the computer name...\n";
print "Hostname name from DHCP is \"$host\"\n";
$host =~ m/^(([A-Z]|[a-z]|[0-9]|-)+)(..*)/;
my $short_host = $1;
my $dns_domain = $3;
if( ! defined($short_host))
{
# if we couldn't get a value for the hostname from the DHCP assigned
# value, don't worry. Just go with the unattend,txt default of value
# entered at prompt
print "WARNING: Couldn't set computer name from hostname. Hostname should be fully qualified domain name using only A-Z, a-z, 0-9 and -.\n\nUsing default from unattend.txt or prompt of $default_computer_name instead\n";
sleep 10;
}
else
{
print "Success! Computer name will be \"$1\". \nDomain name is: $3\n";
$u->{'UserData'}->{'ComputerName'} = $short_host;
sleep 3;
}
[IanGibbs] <flash666 at yahoo.com>
cool
Wiki: IanGibbs
Wiki: Scripts
Wiki: SetComputerNameFromDnsScriptWithFallback