My current environment requires that PowerShell 2.0 compliance be adhered to as we still have server 2003. I am seeing interesting behavior when using the ‘System.Net.Dns::GetHostEntry(“computername”)’. When running the command against a remote machine name the proper (single) entry from DNS is returned. If I run the same command as follows on that remote computer while logged in locally to it ‘System.Net.Dns::GetHostEntry($env:Computername)’ it returns all local IP addresses whether in DNS or not. Is this expected behavior? I have spent hours searching forums for someone else experiencing the same issue but haven’t been successful.
Ultimately my goal is to only return what is actually registered in DNS and not something local.
You’re probably just seeing normal DNS behavior, nothing to do with PowerShell. Keep in mind that a computer will normally cache its own IP addresses indefinitely, locally. So the “name resolution system” will return those, on that computer, without needing to resort to the DNS server. That’s kind of how lookup is supposed to work.
If your goal is to just check the DNS server, then you don’t want name resolution - you want to query the DNS server directly. If it’s a Microsoft DNS server, there’s a WMI namespace you can use for that. You’d connect to the server directly via Get-WmiObject and request whatever specific record(s) you want.
It returns that line of text, which is written to STDOUT (file descriptor 2 - see redirection in code below to the file “tmp.tmp”) and the router/DNS server IP as well as the actual result (last).
I guess your version does work since you skip the first STDOUT result, ignore STDERR (dumped to screen and just happily ignored?), and then get the second one, but calling “findstr” from PowerShell? That’s bad. Very bad.