title: Exception calling "GetHostEntry" with "1" argument(s): "No such device or address"
body: <p>The <code>FQDN</code> for this machine:</p>
  
  <pre><code>thufir@dur:~$ 
  thufir@dur:~$ hostname --fqdn
  dur.bounceme.net
  thufir@dur:~$ 
  </code></pre>
  
  <p>Yes...working <a href="https://stackoverflow.com/a/48807254/262852">directly</a> with <code>powershell</code> gives the <code>FQDN</code> of <code>dur.bounceme.net</code> okay:</p>
  
  <pre><code>thufir@dur:~/powershell$ 
  thufir@dur:~/powershell$ pwsh
  PowerShell v6.0.1
  Copyright (c) Microsoft Corporation. All rights reserved.
  
  https://aka.ms/pscore6-docs
  Type 'help' to get help.
  
  PS /home/thufir/powershell&gt; 
  PS /home/thufir/powershell&gt; [System.Net.Dns]::GetHostByName((hostname)).HostName                                        
  dur.bounceme.net
  PS /home/thufir/powershell&gt; 
  </code></pre>
  
  <p>but what if I want to iterate over an array?  How do I get the <code>FQDN</code> to show as <code>dur.bounceme.net</code>?</p>
  
  <pre><code>thufir@dur:~/powershell$ 
  thufir@dur:~/powershell$ ./hostname.ps1 
  dur.bounceme.net
  beginning loop
  google.com
  Exception calling "GetHostEntry" with "1" argument(s): "No such device or address"
  At /home/thufir/powershell/hostname.ps1:14 char:3
  +   $fqdn = [System.Net.Dns]::GetHostEntry($i).HostName
  +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
  + FullyQualifiedErrorId : ExtendedSocketException
  
  google.com
  localhost
  end
  thufir@dur:~/powershell$ 
  </code></pre>
  
  <p>script:</p>
  
  <pre><code>#!/usr/bin/pwsh -Command
  
  
  #hostname is a reserved variable name?
  
  [System.Net.Dns]::GetHostByName((hostname)).HostName
  
  
  "beginning loop"
  
  $hosts = ("google.com", "hostname", "localhost")
  
  foreach($i in $hosts) {
    $fqdn = [System.Net.Dns]::GetHostEntry($i).HostName
    write-host $fqdn
  }
  
  
  "end"
  </code></pre>
  
  <p>I've tried removing quote marks from around <code>hostname</code> and prepending the dollar sign <code>$</code>.  This is a reserved word?  </p>
  
  <p>Bonus points for explaining the terminology involved.</p>