For a change i am asking a powershell question here
$zone = 'xxx.com'
$range = 'xx.xx.xx.1', 'xx.xx.xx.254'
function Addr2UInt($addr) {
$bytes = $addr.GetAddressBytes()
[array]::Reverse($bytes)
[BitConverter]::ToUInt32($bytes, 0)
}
$addrFrom = Addr2UInt ([Net.IPAddress]::Parse($range[0]))
$addrTo = Addr2UInt ([Net.IPAddress]::Parse($range[1]))
$date = (Get-Date).ToString('MMM-dd-yyyy-hh-mm-ss-tt')
Get-DNSServerResourceRecord $zone -RRType 'A' -ComputerName $DnsServer | ? {
$addr = Addr2UInt $_.RecordData.IPv4Address;
$addrFrom -le $addr -and $addr -le $addrTo
}
on the sceen the o/p is as expected
HostName | RecordType Timestamp | TimeToLive | RecordData |
-------- | ---------- --------- | ---------- | ---------- |
Where RecordData shows me IP
But if i do
Get-DNSServerResourceRecord $zone -RRType 'A' -ComputerName $DnsServer | ? {
$addr = Addr2UInt $_.RecordData.IPv4Address;
$addrFrom -le $addr -and $addr -le $addrTo
} | Export-csv -path C:\temp\x-$date.csv -NoTypeInformation
i do not get the RecordData as below
RecordData |
DnsServerResourceRecordA |
Please help on this.
Try like this
Get-DNSServerResourceRecord $zone -RRType 'A' -ComputerName $DnsServer | Where{
$addr = (Addr2UInt $_.RecordData.IPv4Address)
$addrFrom -le $addr -and $addr -le $addrTo
} |
Select Hostname,RecordType,Timestamp,TimeToLive,@{N='IP';E={$_.RecordData.IPv4Address}} |
Export-csv -path C:\temp\x-$date.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you already try like this?
Get-DNSServerResourceRecord $zone -RRType 'A' -ComputerName $DnsServer | ? {
$addr = Addr2UInt $_.RecordData.IPv4Address;
$addrFrom -le $addr -and $addr -le $addrTo
} |
Select Hostname,RecordType,Timestamp,TimeToLive,RecordData |
Export-csv -path C:\temp\x-$date.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD yes, but the output shows below
RecordData |
DnsServerResourceRecordA |
Try like this
Get-DNSServerResourceRecord $zone -RRType 'A' -ComputerName $DnsServer | Where{
$addr = (Addr2UInt $_.RecordData.IPv4Address)
$addrFrom -le $addr -and $addr -le $addrTo
} |
Select Hostname,RecordType,Timestamp,TimeToLive,@{N='IP';E={$_.RecordData.IPv4Address}} |
Export-csv -path C:\temp\x-$date.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That did worked !
Strange tho
normal output shows this without export to csv ie IP shows fine under recorddata
HostName | RecordType Timestamp | TimeToLive | RecordData | |
-------- | ---------- --------- | ---------- | ---------- | |
xxx | A | 0 | 01:00:00 | xx.xx.xx.xx |
LucD
I see one more odd thing in the output
Each record is 2 times, one without FQDN & one with
xx |
xx.xx.com |
I assume that is normal, if you want to only see the FQDN entries add the -ZoneName parameter, or use a Where-clause.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference