Getting DNS_HOSTNAME to work in windows

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
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”

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

Else {($hostname = $context[“SET_HOSTNAME”])
if ($hostname) {
$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem


so far works like a charm hope this can help some one else

Thank you! I have opened an issue with a link to your example. I hope it’ll be possible to use internal resolving functions, instead of depending on external DLL. If you want, you can try to make the change in code on your own and open pull request against mentioned repo.

Best regards,
Vlastimil Holer