{"id":1362,"date":"2015-08-10T09:15:01","date_gmt":"2015-08-10T13:15:01","guid":{"rendered":"http:\/\/enterpriseadmins.org\/blog\/?p=1362"},"modified":"2020-11-22T10:02:46","modified_gmt":"2020-11-22T15:02:46","slug":"do-you-have-any-way-of-getting-ips-from-a-list-of-server-names","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/do-you-have-any-way-of-getting-ips-from-a-list-of-server-names\/","title":{"rendered":"Do you have any way of getting IPs from a list of server names?"},"content":{"rendered":"<p>A few days ago, someone asked a very basic question. Where is the opposite version of this script:<br \/><a href=\"http:\/\/enterpriseadmins.org\/blog\/scripting\/do-you-have-any-way-of-getting-server-name-from-the-attached-list-of-ips\/\">http:\/\/enterpriseadmins.org\/blog\/scripting\/do-you-have-any-way-of-getting-server-name-from-the-attached-list-of-ips\/<\/a>? They had a list of host names and wanted the associated IP addresses. Since it is somewhat common for a name to resolve to multiple IP addresses, this function has a few more lines as it will loop through each result.<\/p>\n\n\n<pre class=\"wp-block-code\"><code>Function Get-HostIP (&#91;string]$hostName) {\n  try {\n    &#91;system.net.dns]::GetHostByName($hostName).AddressList | %{\n      New-Object psobject -Property @{\n        HostName = $hostName\n        IPAddress = $_.IPAddressToString\n      } # End result object\n    } # end foreach loop\n  } catch {\n    New-Object psobject -Property @{\n      HostName = $hostName\n      IPAddress = \"Unknown\/Error\"\n    } # end result object\n  } # end try\/catch\n} # end function<\/code><\/pre>\n\n\n\n<p>Here is a sample result running this function against google.com:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Get-HostIP 'google.com'\n\nIPAddress     HostName\n---------     --------\n173.194.46.67 google.com\n173.194.46.71 google.com\n173.194.46.65 google.com\n173.194.46.66 google.com\n173.194.46.69 google.com\n173.194.46.72 google.com\n173.194.46.70 google.com\n173.194.46.78 google.com\n173.194.46.68 google.com\n173.194.46.73 google.com\n173.194.46.64 google.com<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A few days ago, someone asked a very basic question. Where is the opposite version of this script:http:\/\/enterpriseadmins.org\/blog\/scripting\/do-you-have-any-way-of-getting-server-name-from-the-attached-list-of-ips\/? They had a list of host names and wanted the associated IP addresses. Since it is somewhat common for a name to &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/do-you-have-any-way-of-getting-ips-from-a-list-of-server-names\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1362","post","type-post","status-publish","format-standard","hentry","category-scripting"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=1362"}],"version-history":[{"count":5,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1362\/revisions"}],"predecessor-version":[{"id":1570,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1362\/revisions\/1570"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=1362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=1362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=1362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}