title: How to ignore warning errors?
body: <p>I have the following PowerShell script. It picks up the NetBIOS name of computers within a given IP address. I'm using a pipe so as to dump the results into a text file. The problem is that if an IP address is not available, a warning is printed.</p>
  
  <p>This is the PowerShell script:</p>
  
  <pre class="lang-psh prettyprint-override"><code>function Get-ComputerNameByIP {
  param( $IPAddress = $null )
  BEGIN {
      $prefBackup = $WarningPreference
      $WarningPreference = 'SilentlyContinue'
  }
  PROCESS {
      if ($IPAddress -and $_) {
          throw ‘Please use either pipeline or input parameter’
          break
      } elseif ($IPAddress) {
          ([System.Net.Dns]::GetHostbyAddress($IPAddress))
      } 
      } else {
          $IPAddress = Read-Host “Please supply the IP Address”
          [System.Net.Dns]::GetHostbyAddress($IPAddress)
      }
  }
  END {
      $WarningPreference = $prefBackup
  }
  </code></pre>
  
  <p>This is the error message I wish to ignore:</p>
  
  <blockquote>
    <p>WARNING: The requested name is valid, but no data of the requested type was found</p>
  </blockquote>