Get-DnsServerResourceRecord -ComputerName server -ZoneName zone.com
I want to run this command and get the HostName, RecordType, ZoneName and All RecordData sets.
I have something like so far:
Get-DnsServerResourceRecord zone.com -ComputerName server |
select hostname, recordType, name,
@{Name='ARecordData';Expression={$_.RecordData.IPv4Address}},
@{Name='CNameRecordData';Expression={$_.RecordData.HostnameAlias}}
My issue is two fold.
You can add the zone name as a calculated property just like you do with the record data.
foreach ($zone in $zone_list) { Get-DnsServerResourceRecord -ZoneName $zone -ComputerName server | Select-Object hostname, @{n='ZoneName';e={$zone}}, recordType, ... }
Don't create individual properties, instead use a switch
statement to select the relevant data depending on the record type in a single property.
... | Select-Object hostname ..., @{n='Data';e={ $rr = $_ switch ($rr.RecordType) { 'A' {$rr.RecordData.IPv4Address} 'CNAME' {$rr.RecordData.HostnameAlias} ... } }}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.