none
Writing DNS zone file in powershell RRS feed

  • Question

  • Hi 

    I currently have a code in classic ASP, creating zone files from a MSSQL base. 
    Now wanted to write this over to PowerShell script. 

    Have some examples of how such files can be created from PowerShell? 

    Today I write it like this in classic ASP:

    dim filesys
    set filesys=CreateObject("Scripting.FileSystemObject")
    If filesys.FileExists("" &Server.MapPath("\Domene\admin\Oppdater_servere\Zoner\orginal.txt")&"") Then
       filesys.CopyFile "" &Server.MapPath("\Domene\admin\Oppdater_servere\Zoner\orginal.txt")&"", "" &Server.MapPath("\Domene\admin\Oppdater_servere\Zoner\" & domene & ".hosts")&""
    set FileSysObj = CreateObject("Scripting.FileSystemObject")
    txtFile= "" &Server.MapPath("\Domene\admin\Oppdater_servere\Zoner\" & domene & ".hosts")&""
    set File = FileSysObj.OpenTextFile(txtFile, 2, TristateFalse)
    
    line10 = "$ttl " & dm_ttl & " " & vbLf & "" & _
               "" & domene & ".  IN  SOA  " & ns01 & ". hostmaster.domain.no. (" & vbLf & "" & _
               "      " & dm_serienr & "" & vbLf & "" & _
               "      3600" & vbLf & "" & _
               "      900" & vbLf & "" & _
               "      2419200" & vbLf & "" & _
               "      3600 )" & vbLf & ""
    File.write line10
    
    (Loop start):
    linje20 = "" & sd_navn &"	" & sd_ttl & "	IN	" & sd_rr_type & "	" & sd_pri & "	" & sd_weight & "	" & sd_port & "	" & sd_adresse & "" & vbLf & ""
    File.write linje20
    objRS2.Movenext
    Loop 
    File.close



    Friday, July 11, 2014 7:02 AM

Answers

All replies

  • IIS and ASP questions should be asked in the ASP forum.   http://forums.asp.net/

    On WS2012 there is a PowerShell DNS module.

    http://technet.microsoft.com/en-us/library/jj649850.aspx

    Look in the repositrory for other examples of howto manage DNS from PowerShell.

    DNSCMD is still the easiest way yo make adhoc changes.

    DNSCMD /?


    ¯\_(ツ)_/¯

    Friday, July 11, 2014 8:51 AM
  • I need help writing files in powershell, with data from MSSQL

    Friday, July 11, 2014 9:16 AM
  • I need help writing files in powershell, with data from MSSQL

    Start here. there are many examples and some videos.

    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

    To do simple output:

    "the is an output line" | Out-File myfile.txt -append

    Outside of this direction - your question is too vague.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, July 11, 2014 9:21 AM
    • Marked as answer by Pål Skodjevåg Friday, July 11, 2014 10:32 AM
    Friday, July 11, 2014 9:20 AM
  • Thanks!

    You got me on the right track 
    Here is an example of how I solved it
    "zone ""$dm_domene"" { `n `
        type master; `n `
        file ""/etc/bind/master/$dm_domene.hosts""; `n `
            allow-update { none; }; `n `
            notify yes; `n `
            allow-transfer { `n `
                      $ns02_ip; `n `
                      $ns03_ip; `n `
                      }; `n `
            also-notify { `n `
                      $ns02_ip; `n `
                      $ns03_ip; `n `
                      }; `n `
      }; " `
        | Out-File c:\script\myfile.txt -append

    Friday, July 11, 2014 10:36 AM