[英]PowerShell - OR operator
我正在尝试运行此命令以获取A和CNAME记录,但它似乎不起作用,我的语法错误。 它仅检索CNAME类型的DNS记录。
实际命令是:Get-DnsServerResourceRecord -RRType“ CNAME”
$results = Get-DnsServerZone | % {
$zone = $_.zonename
Get-DnsServerResourceRecord $zone -filter {(RRType -like "CNAME") -or (RRType -like "A")} | select @{n='ZoneName';e={$zone}}, HostName, RecordType, @{n='RecordData';e={if ($_.RecordData.IPv4Address.IPAddressToString) {$_.RecordData.IPv4Address.IPAddressToString} else {$_.RecordData.NameServer.ToUpper()}}}
}
$results | Export-Csv -NoTypeInformation c:\temp\DNSRecords10.csv -Append
您应该使用Where-Object
进行过滤,因为cmdlet没有自己的参数:
Get-DnsServerResourceRecord -ZoneName $zone |
Where-Object { $_.RRType -in 'CNAME', 'A' } |
Select-Object -Property @(
@{ Name = 'ZoneName'
Expression = { $zone }
}
'HostName'
'RecordType'
@{ Name = 'RecordData'
Expression = {
if ($_.RecordData.IPv4Address.IPAddressToString) {
$_.RecordData.IPv4Address.IPAddressToString
} else {
$_.RecordData.NameServer.ToUpper()
}
}
}
)
作为一个注脚, -like
是一样的使用-eq
,如果你不使用通配符。
说明文件:
TheIncorrigible1提出的解决方案的替代方法是简单地发出两个查询:
@(
Get-DnsServerResourceRecord $zone -RRType CNAME
Get-DnsServerResourceRecord $zone -RRType A
) | select @{n='ZoneName';e={$zone}}, HostName, RecordType, @{n='RecordData';e={if ($_.RecordData.IPv4Address.IPAddressToString) {$_.RecordData.IPv4Address.IPAddressToString} else {$_.RecordData.NameServer.ToUpper()}}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.