I am retrieving the hosts file on a server with 5 DNS entries:
C:\Windows\System32\drivers\etc\hosts
Mine looks like this after the comments:
127.0.0.1 infspcpd8tx8e.rtmphost.com
127.0.0.1 infspkbpef39p.rtmphost.com
127.0.0.1 infspo99vn3ti.rtmphost.com
127.0.0.1 infspqx6l10wu.rtmphost.com
127.0.0.1 infspvdkqjhkj.rtmphost.com
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.
So I have an array that is gotten like so: $ACCOUNTS = Get-ChildItem "D:\cyst\accounts\" | select name
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.
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"
}
}
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.