I want to retrieve the current computer name as an FQDN on a windows 7 machine e.g. computername.companyname.local. How to achieve this?
To return it as a string:
gwmi Win32_ComputerSystem| %{$_.DNSHostName + '.' + $_.Domain}
Using framework .NET this is working on my domain :
([system.net.dns]::GetHostByName("localhost")).hostname
You can also find the information here under (but you have to rebuild it):
[System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
I'm not running on a machine with a real domain, so I can't be 100% sure, but I think that this could work for you:
get-wmiobject Win32_NetworkAdapterConfiguration | where {$_.DNSHostName} | select @{n="FQDN";e={$_.DNSHostName + "." + $_.DNSDomain } } | format-table
For my Thinkpad laptop, this returns something like this:
FQDN
----
t500.home