I will start out by saying I am not very good powershell but I think I have found a way to get DNS_Hostname variable to work in windows, maybe some one out there can tweak to make it cleaner.
First I put this dll in my context files http://simpledns.com/dns-client-lib.aspx
Then I edit the rename function in context.ps1
function renameComputer($context) {
$dnshostname = "DNS_HOSTNAME"
if ($context[$dnshostname] -eq “YES”) {
$dnsclient = $contextDrive.Name + “JHSoftware.DnsClient”
[System.Reflection.Assembly]::LoadFile($dnsclient)
Write-Host $dnsclient
$dnsip = Get-NetIPAddress -AddressFamily IPv4 |where { $_.InterfaceAlias -notmatch ‘Loopback’}
$hostname = [JHSoftware.DNSClient]::LookupReverse($dnsip.IPAddress) -replace ‘(.+?)…+’,’$1’
Write-Output $hostname | add-content c:\hostname.txt
$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem
$ComputerInfo.rename($hostname)
}
Else {($hostname = $context[“SET_HOSTNAME”])
if ($hostname) {
$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem
$ComputerInfo.rename($hostname)
}
}
}
so far works like a charm hope this can help some one else