Is there a way in PowerShell to list DNS records that start with or include some consecutive characters

Soar 116 Reputation points
2023-04-15T02:35:46.4033333+00:00

I use Get-DnsServerResourceRecord with or without -Name XYZ to list all/some DNS records or a specific record named XYZ. How about if I want to list those records starting with X or including Y? Is there a way?

Note: I selected Azure DNS tag because there isn't another relevant tag. But the DNS I'm managing isn't Azure.

Azure DNS
Azure DNS
An Azure service that enables hosting Domain Name System (DNS) domains in Azure.
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Answer accepted by question author
  1. Boris Von Dahle 3,221 Reputation points
    2023-04-15T06:01:01.22+00:00

    Hello,

    There is a way :

    $DnsZone = "yourdomain.com" # Replace with your DNS zone name
    $DnsServer = "yourdnsserver" # Replace with your DNS server name or IP address
    $FilterString = "example" # Replace with the consecutive characters you want to search for
    # Get DNS records from the specified zone
    $DnsRecords = Get-DnsServerResourceRecord -ZoneName $DnsZone -ComputerName $DnsServer
    # Filter records based on the consecutive characters
    $FilteredRecords = $DnsRecords | Where-Object { $_.HostName -like "*$FilterString*" }
    # Display the filtered records
    $FilteredRecords
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.