VMware Cloud Community
esxi1979
Expert
Expert
Jump to solution

PoweShell Q

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.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
esxi1979
Expert
Expert
Jump to solution

LucD yes, but the output shows below

RecordData
DnsServerResourceRecordA
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
esxi1979
Expert
Expert
Jump to solution

That did worked !

Strange tho

normal output shows this without export to csv ie IP shows fine under recorddata

HostName              RecordType Timestamp        TimeToLive  RecordData
--------              ---------- ---------        ----------  ----------
xxxA      0                01:00:00    xx.xx.xx.xx
0 Kudos
esxi1979
Expert
Expert
Jump to solution

LucD

I see one more odd thing in the output

Each record is 2 times, one without FQDN & one with

 

xx
xx.xx.com
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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