resolver101
resolver101

Reputation: 2255

powershell: how to retrieve the computer name in dns format

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?

Upvotes: 2

Views: 7143

Answers (3)

JPBlanc
JPBlanc

Reputation: 72680

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()

Upvotes: 3

Rynant
Rynant

Reputation: 24343

To return it as a string:

gwmi Win32_ComputerSystem| %{$_.DNSHostName + '.' + $_.Domain}

Upvotes: 2

Darin Strait
Darin Strait

Reputation: 316

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

Upvotes: 0

Related Questions