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

    Question

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

    powershell 3.0 modules: http://technet.microsoft.com/en-us/library/hh801904.aspx

    DNS server module: http://technet.microsoft.com/library/jj649850.aspx

    so far i have used the  Set-DnsServerResourceRecord as detailed here: http://technet.microsoft.com/en-us/library/jj649911.aspx

    the code: 

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

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

    HostName                  RecordType Timestamp            TimeToLive      RecordData              
    --------                  ---------- ---------            ----------      ----------              
    @                         A          0                    03:00:00        old.ip.goes.here

    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. :http://technet.microsoft.com/en-us/library/jj649847.aspx

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

     $NewObj.RecordData.ip  = "192.168.1.1"
    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

Answers

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

    I did this way.....

    $oldobj = get-dnsserverresourcerecord -name "Name" -zonename "zone.com" -rrtype "A"
    $newobj = get-dnsserverresourcerecord -name "Name" -zonename "zone.com" -rrtype "A"
    $updateip = "10.1.1.x"
    $newobj.recorddata.ipv4address=[System.Net.IPAddress]::parse($updateip)
    Set-dnsserverresourcerecord -newinputobject $newobj $oldinputobject $oldobj -zonename "zone.com" - passthru

    -----------------
    Succeeded changing the ip "


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

    • Marked as answer by mikster22 Monday, March 25, 2013 5:12 PM
    Monday, March 25, 2013 5:11 AM