Hello there
I am a beginner with this so bare with me:)
I have a script that goes like this:
# Environment Setup
$InputFile = "servers.csv"
# Read the input file which is formatted as name,type,address with a header row
$records = Import-CSV "C:\scripts\$InputFile"
# Now loop through the file to check records
ForEach ($record in $records)
{
# Capture the record contents as variables
$recordName = $record.name
$recordType = $record.type
$recordAddress = $record.address
$resolve= "Resolve-DnsName $recordName"
Invoke-Expression $resolve
if ($resolve.ipaddress -match $recordAddress) {Write-Host -nonewline "Using the Right ip" -fore green}
if ($resolve.ipaddress -notmatch $recordAddress) {Write-Host -nonewline "Using the Wrong ip" -fore red}
}
my input file(servers.csv) looks like this(just an example, in reality I only get one reply per host):
name,type,address
fox.com,A,23.15.9.161
hbo.com,A,206.208.179.53
cnn.com,A,157.166.226.25
what im seing is always the first line with data in the file(in the example fox.com)
gets resolved fine but it doesn't get match only the lines after that.
looks like this(have some problem pasting, only where it says "Using the right ip.." is in green the rest is white):
Name Type TTL Section IPAddress any idea why that is?(don't mind that some might not match sometimes because dns round robin in my environment there is only one match but ti still doesn't work right for the first record, you can change it to anything you like even if the results do match it doesn't say it matches) Thanks in advance
---- ---- --- ------- ---------
fox.com A 464 Answer 23.15.9.138
fox.com A 464 Answer 23.15.9.169
fox.com A 464 Answer 23.15.9.163
fox.com A 464 Answer 23.15.9.178
fox.com A 464 Answer 23.15.9.160
fox.com A 464 Answer 23.15.9.155
fox.com A 464 Answer 23.15.9.136
fox.com A 464 Answer 23.15.9.153
fox.com A 464 Answer 23.15.9.146
Using the Right iphbo.com A 292 Answer 206.208.179.53
Using the Right ipcnn.com A 184 Answer 157.166.226.26
cnn.com A 184 Answer 157.166.226.25
Using the Right ip