#Step 1 - Make sure PING works in PS. For a single server, you
can find the IP address as below:
#By the way,if your PING shows IP6 Addreess, you can prefer
IPv4 over IPv6 in prefix policies. See
https://support.microsoft.com/kb/929852?wa=wsignin1.0 for details.
PS SQLSERVER:\> ping xu-acer-pc
<#
Pinging XU-Acer-PC [192.168.0.39] with 32 bytes of data:
Reply from 192.168.0.39: bytes=32 time<1ms TTL=128
Reply from 192.168.0.39: bytes=32 time<1ms TTL=128
Reply from 192.168.0.39: bytes=32 time<1ms TTL=128
Reply from 192.168.0.39: bytes=32 time<1ms TTL=128
Ping statistics for 192.168.0.39:
Packets: Sent = 4,
Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms,
Maximum = 0ms, Average = 0ms
#>
# Or you can use a variable.
PS SQLSERVER:\>
$server="Xu-Acer-PC"
PS SQLSERVER:\>
ping $Server
# Step 2 - It's hard to retrieve the IP Address from the above
result. But you can use the test-connection command as below:
PS SQLSERVER:\>
$a=(test-connection "Xu-Acer-PC"
-count 1).IPV4Address
PS SQLSERVER:\>
$a.IPAddressToString
192.168.0.39
# Step 3 - How to find the server's DNS
PS SQLSERVER:\>
$DNS=([System.Net.DNS]::GetHostEntry("Xu-Acer-PC")).HostName
PS SQLSERVER:\>
$DNS
#XU-Acer-PC
# Step 4 - How to get the IP Address from the DNS(a convoluted
way)
PS SQLSERVER:\>
$DNS=([System.Net.DNS]::GetHostEntry("Xu-Acer-PC")).HostName
PS SQLSERVER:\>
$DNS
# XU-Acer-PC
PS SQLSERVER:\>
$DNS=([System.Net.DNS]::GetHostEntry("Xu-Acer-PC")).AddressList
PS SQLSERVER:\>
$DNS
<#
Address :
654354624
AddressFamily :
InterNetwork
ScopeId :
IsIPv6Multicast :
False
IsIPv6LinkLocal :
False
IsIPv6SiteLocal :
False
IsIPv6Teredo :
False
IsIPv4MappedToIPv6 : False
IPAddressToString :
192.168.0.39
Address :
AddressFamily :
InterNetworkV6
ScopeId : 0
IsIPv6Multicast :
False
IsIPv6LinkLocal :
False
IsIPv6SiteLocal :
False
IsIPv6Teredo :
False
IsIPv4MappedToIPv6 : False
IPAddressToString : ::1
#>
# returns an array
PS SQLSERVER:\>
$a=$DNS.IPAddressToString
##### you may need to use $DNS |
%{$_.IPAddressToString} in earlier version of PowerShell#####
PS SQLSERVER:\>
$a
<#
192.168.0.39
::1
#>
PS SQLSERVER:\>
$a.getType()
<#
IsPublic IsSerial
Name BaseType
-------- --------
---- --------
True
True Object[] System.Array
#>
# retrieve the IPV4 addressonly
PS SQLSERVER:\>
$a[0]
# 192.168.0.39