DNS A record update usig Powershell 3.0 DNSServer Module in windows server 2012


  • i want to create a simple powershell code to update the A records, 

    powershell 3.0 modules:

    DNS server module:

    so far i have used the  Set-DnsServerResourceRecord as detailed here:

    the code: 

    Get-DnsServerResourceRecord -ZoneName "" -RRType "A" 'this returns with my servrs current IPv4 Address'

    $NewObj = $OldObj = Get-DnsServerResourceRecord -ZoneName "" -RRType "A" -RRData "" $NewObj.RecordData = "" $NewObj.TimeToLive = [System.TimeSpan]::FromHours(3) Set-DnsServerResourceRecord -NewInputObject $NewObj -OldInputObject $OldObj -ZoneName "" -PassThru

    HostName                  RecordType Timestamp            TimeToLive      RecordData              
    --------                  ---------- ---------            ----------      ----------              
    @                         A          0                    03:00:00

    my code works, except it just puts the same ip address back in, i want it to enter a pre specified ip adress, as the ip address falls under the Record data colum i though newObj.RecordData may allow me to specify the IP address to use, however i am unsure about how to tell it  to use an ip address, i have tryed specifiing paramaters such as

    •  InternetAddress

    • IPv4Address

    i got these paramators from a artical about adding dns resource records. :

    i believe all i need is to know the paramator to add after RecordData somthing lie this

     $NewObj.RecordData.ip  = ""
    i am aware that it is possible using a CSV and WMI commands, however i would like to achieve this using native power shell cmdlets. i plan to use this program to update dns records for my dynamic ip server, but this is the starting block.

    Michael Booth

    Sunday, March 24, 2013 9:19 PM


  • Hey Mike...Had a good learning due to this..

    I did this way.....

    $oldobj = get-dnsserverresourcerecord -name "Name" -zonename "" -rrtype "A"
    $newobj = get-dnsserverresourcerecord -name "Name" -zonename "" -rrtype "A"
    $updateip = "10.1.1.x"
    Set-dnsserverresourcerecord -newinputobject $newobj $oldinputobject $oldobj -zonename "" - passthru

    Succeeded changing the ip "

    Thanks Azam When you see answers please Mark as Answer if as helpful.

    Monday, March 25, 2013 5:11 AM