[英]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.