Pointer Record

Roger Roger 7,181 Reputation points
2021-06-02T04:50:44.967+00:00

Hi All

i have a csv file in the below format
HostName IP
Server01 192.168.5.10
Server02 192.168..5.11

Please guide me how to create pointer records using powershell.
for example i have Reverse Lookup Zone 5.168.192.in.addr.arpa. i want to create a pointer record for the server server01 pointing to 192.168.5.10
if the reverse lookup zone 5.168.192.in.addr.arpa doesn't exist then reverse lookup zone should be created.

i want to try the below script but not sure. please guide me.

$ServerName = "MYDC01"
$domain = "contoso.com"
import-csv C:\srv.csv | ForEach-Object {
$Computer = "$($.HostName).$domain"
$addr = $
.IP -split "."
$RLZ = "${$addr[1]}.${$addr[0]}.in-addr.arpa"
dnscmd $Servername /zoneadd $RLZ /primary
dnscmd $Servername /recordadd $rzone "${$addr[3]}.${$addr[2]}" PTR $HostName
}

Windows for business Windows Client for IT Pros Networking Network connectivity and file sharing
Windows for business Windows Server User experience PowerShell
Microsoft Security Microsoft Entra Microsoft Entra ID
{count} votes

Accepted answer
  1. Anonymous
    2021-06-03T03:07:19.887+00:00

    Hi,

    As RichMatheisen-8856 pointed out above, if the DNS server is "MYDC01" and you run the script on "JumpServer01", you could specify the DNS server with the "-ComputerName" parameter.

    $ServerName = "MYDC01"  
    $domain = "contoso.com"  
    import-csv C:\srv.csv | ForEach-Object {  
        $Computer = "$($_.HostName).$domain"  
        $addr = $_.IP -split "\."  
        $RLZ = "$($addr[2]).$($addr[1]).$($addr[0]).in-addr.arpa"  
        if($RLZ -notin (Get-DnsServerZone -ComputerName $ServerName).ZoneName){  
            Add-DnsServerPrimaryZone -Name $RLZ -ReplicationScope Forest -ComputerName $ServerName  
        }  
        Add-DnsServerResourceRecordPtr -Name "$($addr[3])" -ZoneName $RLZ -PtrDomainName $Computer -ComputerName $ServerName  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2021-06-02T08:33:17.287+00:00

    Hi,

    Please check to see if this works.

    $ServerName = "MYDC01"  
    $domain = "contoso.com"  
    import-csv C:\srv.csv | ForEach-Object {  
        $Computer = "$($_.HostName).$domain"  
        $addr = $_.IP -split "\."  
        $RLZ = "$($addr[2]).$($addr[1]).$($addr[0]).in-addr.arpa"  
        if($RLZ -notin (Get-DnsServerZone).ZoneName){  
            Add-DnsServerPrimaryZone -Name $RLZ -ReplicationScope Forest  
        }  
        Add-DnsServerResourceRecordPtr -Name "$($addr[3])" -ZoneName $RLZ -PtrDomainName $Computer  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Roger Roger 7,181 Reputation points
    2021-06-02T14:48:16.147+00:00

    I am getting below error
    i have selected $ServerName = "MYDC01" in the error log i am seeing JumpServer01 as i am logged in to jumpserver01 and executing this syntax. i have domain admin rights.

    Get-DnsServerZone : Failed to enumerate zones from the server JumpServer01.
    At line:7 char:22

    • if($RLZ -notin (Get-DnsServerZone).ZoneName){
    • ~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (JumpServer01:root/Microsoft/...S_DnsServerZone) [Get-DnsServerZone], CimException
    • FullyQualifiedErrorId : WIN32 1722,Get-DnsServerZone

    Add-DnsServerResourceRecordPtr : Failed to get the zone information for 5.168.192.in-addr.arpa on server JumpServer01.
    At line:10 char:6

    • Add-DnsServerResourceRecordPtr -Name "$($addr[3])" -ZoneName $RL ...
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (92:root/Microsoft/...sourceRecordPtr) [Add-DnsServerResourceRecordPtr], CimException
    • FullyQualifiedErrorId : WIN32 1722,Add-DnsServerResourceRecordPtr
    0 comments No comments

  3. Rich Matheisen 47,901 Reputation points
    2021-06-02T18:08:32.893+00:00

    If the DNS server is on the machine "MYDC01" the you'll have to add "-ComputerName $ServerName" to the Get-DnsServerZone and Add-DnsServerResourceRecordPtr cmdlets.

    0 comments No comments

  4. Roger Roger 7,181 Reputation points
    2021-06-03T01:21:24.1+00:00

    i am not clear how to add in the syntax

    0 comments No comments

Your answer

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