Pointer Record

Roger Roger 5,731 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 DHCP
Windows DHCP
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.DHCP: Dynamic Host Configuration Protocol (DHCP). A communications protocol that lets network administrators manage centrally and automate the assignment of Internet Protocol (IP) addresses in an organization's network.
1,039 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,508 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,369 questions
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 36,256 Reputation points Microsoft Vendor
    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. Ian Xue (Shanghai Wicresoft Co., Ltd.) 36,256 Reputation points Microsoft Vendor
    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 5,731 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 46,551 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 5,731 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.