To get FQDN of local computer:
PS C:\> [System.Net.Dns]::GetHostByName(($env:computerName))
To get FQDN of Remote computer:
PS C:\> [System.Net.Dns]::GetHostByName("notebook01")
Note:
System.Net.DNS class has a few other useful methods using which you can get FDQN and IP address details.
Refer to http://msdn.microsoft.com/en-us/library/system.net.dns.aspx for more details.
PS C:\> [System.Net.Dns] | Get-Member -Static
There is definately a great deal to know about this subject. I like all of the points you've made.
ReplyDeleteBios Chip Toshiba
Actually for remote computer will only return short name, not the FQDN:
ReplyDelete===================================
C:\> nslookup vcs611
Server: dc1.testlab.local
Address: 10.10.0.21
Name: vcs611.testlab.local
Address: 10.12.16.11
C:\> $mgtSrvIP = "10.12.16.11"
C:\>[System.Net.Dns]::GetHostByAddress("$mgtSrvIP").HostName
VCS611
=================
So I end up doing it like this:
C:\> $mgtSrvIP = "10.12.16.11"
C:\> $mgtSrvName = [System.Net.Dns]::GetHostByAddress("$mgtSrvIP").HostName
C:\> [System.Net.Dns]::GetHostByName("$mgtSrvName")
HostName
--------
VCS611.testlab.local
C:\> $mgtSrvName = [System.Net.Dns]::GetHostByName("$([System.Net.Dns]::GetHostByAddress("$mgtSrvIP").HostName)").HostName
C:\> $mgtSrvName
VCS611.testlab.local