Updates from October, 2008 Toggle Comment Threads | Keyboard Shortcuts

  • Chris 8:28 pm on October 30, 2008 Permalink | Reply
    Tags: , Windows 2008 R2, Windows 7   

    Information from PDC on the Windows Powershell Blog 

    Here is the link to the Windows Powershell Blog about WS2008R2 and W7 having powershell integrated within the OS . Very cool which is why its so important to read up on powershell if your a Windows IT Pro . Seems like the future of all things Microsoft will include powershell . That is definitely not a bad thing .

    WS08r2 and W7

    http://blogs.msdn.com/powershell/archive/2008/10/29/574-reasons-why-we-are-so-proud-and-optimistic-about-w7-and-ws08r2.aspx

    I’m not a NY Times reader but here is a link about Powershell and W7

    http://www.nytimes.com/external/idg/2008/10/28/28idg-10-best-feature.html?pagewanted=1

    Also if your interested in Media Center on Windows 7 here is a cool write-up of it :

    http://www.wegotserved.co.uk/2008/10/28/windows-7-media-center-revealed/

    That’s it !

    Chris

    Advertisements
     
  • Chris 10:17 am on October 20, 2008 Permalink | Reply
    Tags: , , Windows 2008   

    Hi Folks If you are one of those… 

    Hi Folks ,

    If you are one of those lucky people that update DNS records for Windows 2008 then you might find this blog useful . Note:This blog is only for Windows 2008 DNS Server .There is not that much examples on the web for updating the DNS Server .

    Since I do a lot of these updates I wanted to automate the process . I wanted to do this for 2 reasons . One its extremely fast for update 10 A and PTR records with scripting . Second reason is to cut down on errors . You can make errors easily when entering in a PTR record . So lets begin …..

    Before we begin the script that I’m going to walk you thru Creates new A records and PTR records in DNS by reading a csv file . It doesn’t delete records but you can add that functionality easily .

    We start by creating our Params . The way this script will work is by calling the script like this :

    .\Update-DNS.ps1 -forward ServerName -reverse ServerName

    This will become more apparent when I show the help file…

    So my params line is first and it looks like this :


    param ($forward,$reverse,$dnsaddresslist = (Import-Csv ".\dnsaddresslist.csv"),$help)

    The great thing about powershell is that when you define your parameters first in your script ,you are able to use them like switches . So the $forward variable would be -forward SeverName .

    The next section starts our functions starting with the help function :

    function funHelp()

    {
    $helpText=@”

    NAME: Update-DNSAddress.ps1

    DESCRIPTION:
    Creates DNS entries from a csv file called dnsaddresslist.csv .It
    Creates a Forward and Reverse lookup Zone entry in the zone
    servers specified.

    Prerequisites:
    You should have a dnsaddresslist.csv file in the same directory as the script.
    When the script starts it reads this file. An error will occur if the file
    is not present.

    PARAMETERS:

    • forward specifies the forward lookup zone Server (required)
    • reverse specifies the reverse lookup sone Server (required)
    • help Prints Help File

    OTHER:
    -dnsaddresslist Holds dns entry information in the csv file

    SYNTAX:
    .\Update-DNSAddress.ps1 -forward serverName -reverse ServerName

    Creates forward and reverse entries from all devices listed
    in dnsaddresslist.csv to the servers specified .

    “@

    $helpText
    exit
    }

    I cannot take credit for the way this looks I have been reading the Microsoft powershell Book and Ed Wilson who is awesome creates these help functions which is great way to put help documention into a script .

    Next I created a Check to see if the Forward and Reverse Servers are online .

    function funCheck-DNSServersStatus ($forward,$Reverse)
    {

    Write-Host “Verifying if DNS Servers are Reachable…..”

    1. Create our object

    $net = New-Object System.Net.NetworkInformation.Ping

    #Check the Forward lookup Server
    do {$result =$net.send($forward);}
    until ($result.status -eq “Success”)

    #Create message that Server is reachable

    Write-Host “Forward lookup server ,$forward, is reachable …..”

    #Check if the reverese Server is reachable .
    do {$result =$net.send($reverse);}
    until ($result.status -eq “Success”)

    #Create message that the reverse lookup server is reachable

    write-host “Reverse lookup server,$reverse,is reachable……”

    }

    We are passing the function both server name .If you check the function we are using the System.Net.NetworkInformation.Ping Class to communicate with the servers . Like a ping from a command prompt . Then using a Do … until loop .

    Hopefully your DNS servers are up and running 🙂 . You can also add another check to see if the DNS service is running also which would be a good thing to check .

    The next 2 functions are the update . You might be asking by I have separate functions for the forward and the reverse . Its becuase where I work we do A record updates on one server and PTR records on another Server . So the last 2 Functions look like this :

    function funUpdate-forward($forward,$dnsaddresslist)
    {

    1. Domain Name

    $strDomain =”Test.Microsoft.com”

    1. create instance of ResourceRecord

    $objRR = [WmiClass]”\\$forward\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord”

    foreach($a in $dnsaddresslist)
    {
    Write-Host ” Updating forward lookup zone with $a” -ForegroundColor RED

    #create our ip address variable
    $address = $a.Address

    #create our A name record
    $name = $a.Name + “Microsoft.com”

    1. create our String for record creation

    $strRR = $name + ” IN A $address”

    #Update Record now
    $objRR.CreateInstanceFromTextRepresentation($forward,$strDomain,$strRR)

    }

    }

    function funUpdate-Reverse($reverse,$dnsaddresslist)
    {

    1. create instance of ResourceRecord

    $objRR = [WmiClass]”\\$reverse\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord”

    foreach ($a in $dnsaddresslist)
    {

    Write-Host “Updating Reverse Lookup zone with $a” -ForegroundColor Blue

    #create our ip address variable
    $raddress = $a.Address

    #Get the name record
    $rname = $a.Name

    #break the address into octets
    $breakaddress = $raddress.split(‘.’)

    #create octets
    $rFirst = $breakaddress[0] ; $rSecond = $breakaddress[1] ;$rThird = $breakaddress[2] ; $rFourth = $breakaddress[3]

    #create the Reverse lookup String
    $strReverseRR = “$rFourth”+”.”+”$rThird”+”.”+”$rSecond”+” IN PTR $rname.test.microsoft.com”
    $strReverseDomain = “$rFirst”+”.in-addr.arpa.”

    #Call Create Method
    $objRR.CreateInstanceFromTextRepresentation($reverse,$strReverseDomain,$strReverseRR)

    }

    }

    Now lets look at the forward first :

    We are using WMI to update both A and PTR records . So you need to create and instance .What we are doing is creating the IP address variable and Name variable . Then performing the Method Call which creates the record .

    For the Reverse lookup it is much more difficult . We need to create an instance of our WMI object using the MicrosoftDNS_ResourceRecord class . We then read from the csv file and get both the IP and Name . Once we have those variables we reverse the IP address using this bit of code :

    #break the address into octets
    $breakaddress = $raddress.split(‘.’)

    #create octets
    $rFirst = $breakaddress[0] ; $rSecond = $breakaddress[1] ;$rThird = $breakaddress[2] ; $rFourth = $breakaddress[3]

    #create the Reverse lookup String
    $strReverseRR = “$rFourth”+”.”+”$rThird”+”.”+”$rSecond”+” IN PTR $rname.test.microsoft.com”
    $strReverseDomain = “$rFirst”+”.in-addr.arpa.”

    There is a lot going on here . We are breaking up the address then reversing it to create our string to pass to the method which we call to create our PTR record . Notice that in Windows 2008 you don’t have those cascading folders or Domain’s on the PTR zones like Windows 2003 . This script takes that into account so what ever address you are entering (10. or whatever ) it find the correct folder or Zone .

    After going thru our Functions for this script it is time to get to the main portion .

    #Check to see if help text is requested
    if($help) { “Printing help now…”;funHelp}

    #Check to see if forward and reverse arguments have been entered.
    if(!$forward) {“You must Supply a forward lookup zone DNS server” ; funHelp}
    if(!$reverse) {“You must Supply a reverse lookup zone DNS server” ; funhelp}

    1. Show the contents of the txt file and ask the user if they would like to continue

    Write-Host “The following IP address/hosts will be entered in DNS.”

    #contents file
    $dnsaddresslist

    #let the user make a descion if they would like to continue.
    $decision = Read-Host “Would you like to continue Y or N–”

    switch($decision.toupper())
    {
    Y{continue}
    N{exit}
    }

    #Call to verify DNS Servers .
    funCheck-DNSServersStatus $forward $reverse

    #now that we have all the information lets update forward zone
    funUpdate-forward $forward $dnsaddresslist

    #update reverse zone
    funUpdate-Reverse $reverse $dnsaddresslist

    First we are seeing if help parameter has been passed if so it prints the Help file . Next it checks to make sure the Forward and Reverse Servers are passed which are required .

    Next it prints out the csv file and gives the user a decsion to continue or not . Sort of like a warning .After all we are updating some important stuff . 🙂

    Last but not least we call the functions .

    Here is the finished Script :


    ####################################################################
    #ScriptName : update-DNSAddress
    #Created by : Chris Federico
    #Date Created : 09/09/2008
    #Modifications:
    ###################################################################

    param ($forward,$reverse,$dnsaddresslist = (Import-Csv ".\dnsaddresslist.csv"),$help)

    function funHelp()

    {
    $helpText=@”

    NAME: Update-DNSAddress.ps1

    DESCRIPTION:
    Creates DNS entries from a csv file called dnsaddresslist.csv .It
    Creates a Forward and Reverse lookup Zone entry in the zone
    servers specified.

    Prerequisites:
    You should have a dnsaddresslist.csv file in the same directory as the script.
    When the script starts it reads this file. An error will occur if the file
    is not present.

    PARAMETERS:

    • forward specifies the forward lookup zone Server (required)
    • reverse specifies the reverse lookup sone Server (required)
    • help Prints Help File

    OTHER:
    -dnsaddresslist Holds dns entry information in the csv file

    SYNTAX:
    .\Update-DNSAddress.ps1 -forward ServerName -reverse ServerName

    Creates forward and reverse entries from all devices listed
    in dnsaddresslist.csv to the servers specified .

    “@

    $helpText
    exit
    }

    function funCheck-DNSServersStatus ($forward,$Reverse)
    {

    Write-Host “Verifying if DNS Servers are Reachable…..”

    1. Create our object

    $net = New-Object System.Net.NetworkInformation.Ping

    #Check the Forward lookup Server
    do {$result =$net.send($forward);}
    until ($result.status -eq “Success”)

    #Create message that Server is reachable

    Write-Host “Forward lookup server ,$forward, is reachable …..”

    #Check if the reverese Server is reachable .
    do {$result =$net.send($reverse);}
    until ($result.status -eq “Success”)

    #Create message that the reverse lookup server is reachable

    write-host “Reverse lookup server,$reverse,is reachable……”

    }

    function funUpdate-forward($forward,$dnsaddresslist)
    {

    1. Domain Name

    $strDomain =”Microsoft.com”

    1. create instance of ResourceRecord

    $objRR = [WmiClass]”\\$forward\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord”

    1. We have to read in the txt file split it to get IP address and Name

    foreach($a in $dnsaddresslist)
    {
    Write-Host ” Updating forward lookup zone with $a” -ForegroundColor RED

    #create our ip address variable
    $address = $a.Address

    #create our A name record
    $name = $a.Name + “FQDNS_NAME”

    1. create our String for record creation

    $strRR = $name + ” IN A $address”

    #Update Record now
    $objRR.CreateInstanceFromTextRepresentation($forward,$strDomain,$strRR)

    }

    }

    function funUpdate-Reverse($reverse,$dnsaddresslist)
    {

    1. create instance of ResourceRecord

    $objRR = [WmiClass]”\\$reverse\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord”

    foreach ($a in $dnsaddresslist)
    {

    Write-Host “Updating Reverse Lookup zone with $a” -ForegroundColor Blue

    #create our ip address variable
    $raddress = $a.Address

    #Get the name record
    $rname = $a.Name

    #break the address into octets
    $breakaddress = $raddress.split(‘.’)

    #create octets
    $rFirst = $breakaddress[0] ; $rSecond = $breakaddress[1] ;$rThird = $breakaddress[2] ; $rFourth = $breakaddress[3]

    #create the Reverse lookup String
    $strReverseRR = “$rFourth”+”.”+”$rThird”+”.”+”$rSecond”+” IN PTR $rname.microsoft.com

    $strReverseDomain = “$rFirst”+”.in-addr.arpa.”

    #Call Create Method
    $objRR.CreateInstanceFromTextRepresentation($reverse,$strReverseDomain,$strReverseRR)

    }
    }

    #Check to see if help text is requested
    if($help) { “Printing help now…”;funHelp}

    #Check to see if forward and reverse arguments have been entered.
    if(!$forward) {“You must Supply a forward lookup zone DNS server” ; funHelp}
    if(!$reverse) {“You must Supply a reverse lookup zone DNS server” ; funhelp}

    1. Show the contents of the txt file and ask the user if they would like to continue

    Write-Host “The following IP address/hosts will be entered in DNS.”

    #contents file
    $dnsaddresslist

    #let the user make a descion if they would like to continue.
    $decision = Read-Host “Would you like to continue Y or N–”

    switch($decision.toupper())
    {
    Y{continue}
    N{exit}
    }

    #Call to verify DNS Servers .
    funCheck-DNSServersStatus $forward $reverse

    #now that we have all the information lets update forward zone
    funUpdate-forward $forward $dnsaddresslist

    #update reverse zone
    funUpdate-Reverse $reverse $dnsaddresslist

    **** Update … I forgot to mention the csv file should look like this :

    Name,Address

    09/2011 – Links to updated script and CSV file .
    http://dl.dropbox.com/u/43877820/dnsaddresslist.csv
    http://dl.dropbox.com/u/43877820/Update-DNSAddress..txt

     
    • Dan 5:10 pm on February 3, 2010 Permalink

      So what do I need to do to run this in my environment? Anything I need to change in the script to match my environment? How do I run this script?

    • calros 6:25 pm on August 17, 2010 Permalink

      great, but I already have the records in DNS forward loockup zone, I need to just modify some of them by changing their IP address, any idea how can I get this done?

    • Chris 8:52 pm on August 18, 2010 Permalink

      Hi Calros ,

      I have changed this script from this post . I should post an updated version . I basically delete the forward lookup zone entry . Then re-run the script to populate the correct IP . It is pretty fast and saves time. Please let me know if you like I can e-mail it to you .I should be putting up an updated post on this soon .

    • Alan 1:34 pm on September 21, 2010 Permalink

      Nice script Chris! I have a bunch of Windows based DNS updates to do as part of a migration and would be VERY interested in your new script.. Could you blast me a copy @ ledphoot@gmail.com ?

      Much appreciated…

      Alan

    • Chris 6:59 pm on September 21, 2010 Permalink

      Sure Alan E-mailing it you now … hope that it helps 🙂

    • Dmitry 9:34 am on September 30, 2010 Permalink

      Hey.
      Seems like with the do {} until () checks in the forward and reverse server pings the script will fall into an infinite loop if the servers are down, no ? 🙂

    • Chris 12:48 pm on September 30, 2010 Permalink

      Hi Dmitry ,

      Yes your correct … you can change that behavior . I just wanted a check to see if the DNS server was reachable before trying to add records .

    • Michael 7:42 am on December 7, 2010 Permalink

      Hey Chris
      Thank you for this fantastic script.
      I have some troubles with the csv File:
      It always tries to do “Updating Reverse Lookup zone with @{name=Test2.matrix.local; ip=192.168.78.52}”
      name and ip are the headers in the csv File… I tried it with and without
      Any ideas?

      Could you maybe send me the actual version of this script (CRASHandburn@gmx.de)???
      Thank you !
      Mike

    • Simon 5:09 am on March 4, 2011 Permalink

      Hi Guys

      New Question: How do i create a new Reverse LookUp Zone, and set Dynamic Updates to “Nonsecure and Secure” and set the Replication to “To all DNS servers running on domain controllers in this forest: mydomain.local”

      I’m creating a script, wich is puling scope information from my DHCP and then should create matching reverse lookup zones on my dns server. But i need to set the 2 properties i’m asking about.

      Hope someone can help…

    • Wberryman 9:32 pm on July 17, 2011 Permalink

      How do you specify which zone the entries are added into? Is this scripd ran on the CD or remotely? Also in the CSV do you sue the shortname or FQDN? will.berryman@gmail.com

    • squire11 8:02 am on August 9, 2011 Permalink

      Chris – any chance i can get a copy?
      thanks,
      e

    • Chris 10:36 am on August 9, 2011 Permalink

      You betcha .. just sent it …

      Chris

    • Roger 10:35 am on August 18, 2011 Permalink

      Chris, can you send me a copy of the script as well ? Thanks RM

    • Tejas 11:17 am on September 13, 2011 Permalink

      Can you send updated version of batch to me. Also I have one question that i have multidomain environment where my second domain is of 2003 servers with SP2 & R2 mix. Does this script comply with 2003 OS as well? Can you please suggest if not.

    • Tejas 11:18 am on September 13, 2011 Permalink

      Can you send updated version of batch to me. Also I have one question that i have multidomain environment where my second domain is of 2003 servers with SP2 & R2 mix. Does this script comply with 2003 OS as well? Can you please suggest if not. I wrongly putted my email ID before. Correcting it as “tejas.d.kshirsagar@gmail.com”

    • Karl 9:54 am on September 30, 2011 Permalink

      Can you send me a copy of the script and the format of the file, I currently have the reverse zones subnetted – can the script support this

    • Chip 8:48 am on November 4, 2011 Permalink

      When using the updated script to delete records it fails with “The term ‘DNSCMD’ is not recognized as the name of a cmdlet”. Where is DNSCMD supposed to come from?

    • Chip 9:20 am on November 4, 2011 Permalink

      Answering my own question about DNSCMD This is a problem with 64 bit powershell on 2008 R2. It lives in C:\Windows\system32 but is not found because of Filesystem Redirection. The easiest way to get around this is copy dnscmd.exe somewhere else and reference it directly. I copied mine to C:\Scripts\dnscmd.exe and now it works great.

    • Mark 4:33 am on January 27, 2012 Permalink

      Great script! Nice work. I ran into one issue i was wondering if you could help with. It seems the reverse entry isn’t being added. Here is the error.

      ———————————-

      PS H:\IT\PowerShell\In Development\Mark> .\Update-DNSAddress.ps1 -forward gdc.v
      pdc.us -reverse gdc.vpdc.us
      The following IP address/hosts are in the CSV file.

      Name Address
      —- ——-
      test160 10.10.101.160

      Would you like to add or delete these entries from DNS ? Please Enter A or D: A
      Verifying if DNS Servers are Reachable…..
      Forward lookup server ,gdc.vpdc.us, is reachable …..
      Reverse lookup server,gdc.vpdc.us,is reachable……
      Updating forward lookup zone with @{Name=test160; Address=10.10.101.160}

      Updating Reverse Lookup zone with @{Name=test160; Address=10.10.101.160}
      Exception calling “CreateInstanceFromTextRepresentation” : “Generic failure ”
      At H:\IT\PowerShell\In Development\Mark\Update-DNSAddress.ps1:150 char:44
      + $objRR.CreateInstanceFromTextRepresentation <<< .\Update-DNSAddress.ps1 -forward gdc.v
      pdc.us -reverse gdc.vpdc.us
      The following IP address/hosts are in the CSV file.

      Name Address
      —- ——-
      test160 10.10.101.160

      Would you like to add or delete these entries from DNS ? Please Enter A or D: D
      Verifying if DNS Servers are Reachable…..
      Forward lookup server ,gdc.vpdc.us, is reachable …..
      Reverse lookup server,gdc.vpdc.us,is reachable……
      Deleting @{Name=test160; Address=10.10.101.160} from forward lookup Zone …….
      ..

      Deleted A record(s) at vpdc.us
      Command completed successfully.

      Deleting @{Name=test160; Address=10.10.101.160} from Reverse Lookup Zone……..
      .

      Command failed: DNS_ERROR_ZONE_DOES_NOT_EXIST 9601 0x2581

      PS H:\IT\PowerShell\In Development\Mark>

    • RJ 4:14 pm on February 29, 2012 Permalink

      I am getting the same error that Mark did. Reverse entries are not being added.

      Updating Reverse Lookup zone with @{Name=Server01; Address=192.168.0.1}
      Exception calling “CreateInstanceFromTextRepresentation” : “Generic failure ”
      At C:\Update-DNSAddress.ps1:150 char:44
      + $objRR.CreateInstanceFromTextRepresentation <<<< ($reverse,$strReverseDomain,$strReverseRR)
      + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : WMIMethodException

      Any ideas?

      -RJ

    • Chris 4:19 pm on February 29, 2012 Permalink

      This generic failure can happen when you don’t have a reverse look up defined for the zone . So if the Zone is not there it will not create it . It can also be a permissioning thing . It is hard to say … being that its generic .

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel