如果我运行命令
$alldns = Get-DnsServerResourceRecord -computername dns-server -ZoneName "domain.com" -RRType "A"
它完美无缺,显示了ip地址:
pc2 A 1 10/24/2017 6:00:0... 00:20:00 192.168.1.149
Gaming A 1 10/24/2017 6:00:0... 00:20:00 192.168.1.139
dc A 1 0 01:00:00 192.168.1.50
dc2 A 1 0 01:00:00 192.168.1.51
Surface A 1 10/24/2017 8:00:0... 00:20:00 192.168.1.141
server1 A 1 10/19/2017 7:00:0... 00:20:00 192.168.1.200
但如果我运行附加命令
$alldns = Get-DnsServerResourceRecord -computername dns-server -ZoneName "domain.com" -RRType "A" | Select-Object -Property Hostname, RecordData, Timestamp
我得到了这个结果,ip消失了,并被DnsServerResourceRecordA取代。请指教。
pc2 DnsServerResourceRecordA 10/24/2017 6:00:00 PM
Gaming DnsServerResourceRecordA 10/24/2017 6:00:00 PM
dc DnsServerResourceRecordA
dc2 DnsServerResourceRecordA
Surface DnsServerResourceRecordA 10/24/2017 8:00:00 PM
server1 DnsServerResourceRecordA 10/19/2017 7:00:00 PM
答案 0 :(得分:2)
您可以通过为calculated property
提取IPv4Address
来完成此操作。在select-object中,您可以按以下方式使用@{Name='RecordData';Expression={$_.RecordData.IPv4Address}}
而不仅仅"RecordData"
Get-DnsServerResourceRecord -computername dns-server -ZoneName "domain.com" -RRType "A" | select-object -Property Hostname,Timestamp, @{Name='RecordData';Expression={$_.RecordData.IPv4Address}}
有关calculated property
的更多详细信息:https://technet.microsoft.com/en-us/library/ff730948.aspx?f=255&MSPPError=-2147217396
或者
可以使用Recorddata
提取 ExpandProperty
。您必须在select-object中使用-ExpandProperty
,其余(Hostname,Timestamp)可以使用-Property
提取。您将在下方使用IPv4Address
字段。
Get-DnsServerResourceRecord -computername dns-server -ZoneName "domain.com" -RRType "A" | select-object -ExpandProperty recorddata -Property Hostname,Timestamp
有关expandproperty
的更多信息:https://blogs.msdn.microsoft.com/vishinde/2012/08/27/expandproperty-in-select-object/
无论哪种方式,您都可以使用正确的IP地址替换DnsServerResourceRecordA
..