title: Powershell: Trying To Match a Variable Against an Array using Get-Content
body: <p>I am retrieving the hosts file on a server with 5 DNS entries:</p>
  
  <p>C:\Windows\System32\drivers\etc\hosts</p>
  
  <p>Mine looks like this after the comments:</p>
  
  <blockquote>
    <p>127.0.0.1 infspcpd8tx8e.rtmphost.com</p>
    
    <p>127.0.0.1 infspkbpef39p.rtmphost.com</p>
    
    <p>127.0.0.1 infspo99vn3ti.rtmphost.com</p>
    
    <p>127.0.0.1 infspqx6l10wu.rtmphost.com</p>
    
    <p>127.0.0.1 infspvdkqjhkj.rtmphost.com</p>
  </blockquote>
  
  <p>In my hosts file I see them as 5 lines on top of eachother, but when I paste it here it has a space inbetween.  This is the same when I use get-content on that file, but I wouldn't expect that to stop me.</p>
  
  <p>So I have an array that is gotten like so:
  $ACCOUNTS = Get-ChildItem  "D:\cyst\accounts\" | select name</p>
  
  <p>I then try to see if there are duplicate entries in the hosts file by checking the $accounts variable against the array I got containing the hosts file.</p>
  
  <pre><code>    foreach ($rtmp in $ACCOUNTS) { 
          $HostsFile = Get-Content C:\Windows\System32\drivers\etc\hosts | ForEach-Object {[System.Convert]::ToString($_)}
          #$rt[string]$data = $HostsFile
          [string]$rtmpfull = $rtmp.name + ".rtmphost.com"
  
              if ($HostsFile -contains $rtmpfull) { Write-Host "Host found in hosts file moving on..." } 
  
                  else { echo "wrong"
  
                  }
          }
  </code></pre>
  
  <p>It never matches and always returns false, I can't match anything.. please help - is it a type issue?  I've googled this for DAYS but now i'm desperate and posting here.</p>