powershell: how to retrieve the computer name in dns format

Go To StackoverFlow.com

2

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?

2012-04-04 20:19
by resolver101


2

To return it as a string:

gwmi Win32_ComputerSystem| %{$_.DNSHostName + '.' + $_.Domain}
2012-04-04 21:13
by Rynant


3

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()
2012-04-05 03:18
by JPBlanc


0

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
2012-04-04 21:04
by darin strait
Ads