Writing DNS zone file in powershell

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

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

Similar Messages

  • DNS ZONE FILES

    HI I need to make changes to the DNS zone file how do i do this

    Hi,
    Updating External DNS files.
    Updating DNS Records with a Domain Registrar
    Both these links discuss making changes to DNS Zone files.
    Hopefully, you'll find an answer there.
    Tricia

  • DNS Zone File

    Start, Run, %SystemRoot%\System32\DNS\
    You will find them there....

    Where is the zone file usually stored on the DC? I've looked in system 32 folder but cannot find it? Thanks
    This topic first appeared in the Spiceworks Community

  • List DNS zones on a NTDS.DIT file is it possible?

    Hi guys,
    is it possible that after mounting an active directory database NTDS.DIT file to list the DNS zones that existed in that domain controller active directory integrated zones?
    I have mounted successfully the AD database using
    dsamain.exe -dbpath “C:\path\to\ntds.dit” -ldapport 5532 -allownonadminaccess -allowupgrade
    and now i can see it on dsa.msc console. But since the DNS folder on that drive didn't had the DNS zone files i assume this are embedded on the database as they were AD integrated.
    Thanks in advance for any information.

    Simply use ldp.exe and you then you can go under:
    CN=MicrosoftDNS,DC=DomainDnsZones,DC=Domain,DC=COM
    CN=MicrosoftDNS,DC=ForestDnsZones,DC=Domain,DC=COM
    This is an example of article about how you can use ldp.exe: https://ramazancan.wordpress.com/2009/12/11/dsamain-%E2%80%93-active-directory-database-mounting-tool/
    This posting is provided AS IS with no warranties or guarantees , and confers no rights.
    Ahmed MALEK
    My Website Link
    My Linkedin Profile
    My MVP Profile

  • Can't create DNS zones in Server Admin

    Hi All,
    So, I've run into this strange problem where when configuring the zone files for the DNS server in Server Admin that clicking on the + button doesn't do anything. I've re-installed Tiger Server including reformating the disk and still nothing.
    Can anyone tell me where the zone file is kept. It might be better just to make my own unless anyone can tell me why the + button isn't working.
    Thanks much!

    Definitely better to make your own, if you know how (lots of good google-able docs on this). Using Server Admin for DNS zone files is dicey at best.
    BIND config file is located at '/etc/named.conf'
    Zone files live in '/var/named/.' Primary zone files are named 'myDomain.com.zone' and secondary files are named 'myDomain.com.bak'
    Feel free to email me if you need some default files.
    Can anyone tell me where the zone file is kept. It
    might be better just to make my own unless anyone can
    tell me why the + button isn't working.
    iBook G4   Mac OS X (10.4.3)  

  • No DNS zones in server admin

    Here's my log: 
    Oct 21 12:49:25 server servermgrd[2019]: -[DNSManagerRRMgr bindZoneDB]: Unable to load zone database (RRs) for "***.com" from file "/var/named/db.***.com": CNAME and other data

    Definitely better to make your own, if you know how (lots of good google-able docs on this). Using Server Admin for DNS zone files is dicey at best.
    BIND config file is located at '/etc/named.conf'
    Zone files live in '/var/named/.' Primary zone files are named 'myDomain.com.zone' and secondary files are named 'myDomain.com.bak'
    Feel free to email me if you need some default files.
    Can anyone tell me where the zone file is kept. It
    might be better just to make my own unless anyone can
    tell me why the + button isn't working.
    iBook G4   Mac OS X (10.4.3)  

  • Creating a diskpart script file using Powershell

    Hi,
    I have a very odd (and very annoying) problem...
    I have a powershell script which creates a diskpart file to online any given number of iSCSI attached disks.  The powershell script takes input from a csv which includes the disk numbers then creates a txt file with the relevent diskpart commands (e.g
    select disk X, online disk, etc..)
    The powershell script runs without error and creates the output file, however when I attempt to run diskpart with the outputfile (i.e. diskpart /s outputfile.txt) diskpart does not acknowledge/accept the file and just returns a list of valid commands. 
    Yet if I manually create a empty txt file via Windows Explorer and copy and paste the contents of the powershell generated script file in to it, then run the diskpart against this file all works as expected.
    So it seems as though that in writing to the file via powershell something is happening to the file fortmatting which diskpart does not like - any ideas what?
    I have tried several work arounds including manually creating the txt file before running the powershell and creating the txt file explicitly from powershell but get the same result.
    Although I can workaround the issue as described above it would be nice to get this working as intended, or least understand why the problem occurs - so any help/advice would (as always) be much appreciated!
    for reference the powershell script is detailed below:
    $a="select disk "
    $b="attributes disk clear readonly"
    $c="online disk"
    import-csv .\input.csv | foreach {
     $a+$_.diskNumber >> outputfile.txt
     $b >> outputfile.txt
     $c >> outputfile.txt

    Kazun,
    Thank you for sharing your script. I tired it but did not work for me. I modified yours slightly to configure 134 SAN devices as mount points.   I've already set the SAN policy to OnlineAll and cofigured 4 other devices. When I run the diskpart
    commands per disk from CLI its works. Please let me know what I'm missing.Thank you.
    $B = import-csv -Path "C:\Support\Prep_Disks\3-CreateMountPoints\MountPoints.csv"
    $B | Foreach-Object {
    $DiskNum = $_.DiskNumber
    $MP = $_.MountPath
    $DiskLBL = $_.DiskLabel
    $command = @"
    SELECT DISK $DiskNum
    ATTRIBUTES DISK CLEAR READONLY
    ONLINE DISK
    CONVERT MBR
    CREATE PARTITION PRIMARY
    ASSIGN MOUNT=$MP
    FORMAT FS=NTFS UNIT=64k LABEL=$DiskLBL QUICK
    $command | diskpart

  • OS X 10.6.1:  bootpd, named, and dynamic DNS zone updates

    I have OS X 10.6.1 installed on a Mac Pro. It is configured to be the name server and DHCP server for my home network, i.e. /etc/named.conf and /etc/bootpd.plist have been modified to provide these services.
    I've encountered no problems with either the name server or the DHCP component of bootpd after upgrading to OS X 10.6(.1); however, one thing that continues to bug me is how to configure bootpd to dynamically update the DNS zone files whenever a lease is issued, released, or expires.
    At work, I use the Internet System Consortium's DHCP software and have it configured to dynamically update DNS whenever leases change state. I would really like to have DNS done the same way at home.
    What changes need to be made to /etc/bootpd.plist that would allow dynamic DNS updates to occur?

    Did you ever get an answer to this? Would rather not change the DHCP server in Snow Leopard....
    Thanks

  • Convert into zip file to .dns file with powershell

    HI
    I am using below command to take DNS zone backup and after zone export I am moving that file to other folder
    with below script.
    DNSCMD /zoneexport contoso.org contoso.org.dns
    Move-Item c:\windows\system32\dns\contoso.org.dns e:\dns\contoso.org.dns
    Now I want to convert.dns file to zip file so that I can send it to mail for all team members.

    Hi there,
    You can use the Write-Zip cmdlet available in the
    PowerShell Community Extensions
    There is a similar thread at below link:
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/8f98f06e-79fe-401c-92f0-a548d4304dcc/how-to-zip-files-and-folders-using-powershell?forum=winserverpowershell
    Hope this helps
    Knowledge is Power{Shell}.

  • What Is an Appropriate Hostname & DNS Zone Configuration for External DNS Setup?

    I setup servers that are hosted on a secure external data centre. The data centre has its own DNSS, so the DNS service is never setup on the server itself, and is handled by the data centre. I have already setup a handful of servers, and they all seem to be working well. Nevertheless, a couple of people in these discussions have told me, that I'm not setting the servers up 'properly' because of the way I'm naming the server - ie., they believe I'm assigning a 'wrong' hostname - and because of the way I'm setting up subdomains in the zone file. Here is how I'm currently doing it:
    CURRENT SETUP:
    The server is public, and it is also the ONLY machine publicly in the domain zone. So, if the client's domain is "example.com", there is only one machine that will respond to all services in that domain. Because of this:
    - Server Hostname: "example.com"
    - reverse DNS PTR record points to "example.com"
    -  'mail.example.com', 'www.example.com', 'ftp.example.com', etc, are all setup as A records that point to the same IP address as "example.com".
    This has been working fine so far. I have not had any problems with any service, including mail. However, a couple of people suggested that "example.com" is not a fully qualified domain name, and that this setup is therefore  'incorrect', and that it will cause me problems in the future. They suggest I should be setting these servers up like this:
    SUGGESTED SETUP:
    - Server Hostname: "server.example.com"
    - reverse DNS PTR record points to "server.example.com"
    - setup "www.example.com" as a record pointing to the same IP address as "server.example.com", but avoid setting up other subdomains unless absolutely necessary - ie., tell client to use "server.example.com" as the 'proper' address for mail/ftp/etc.
    Technically, 'net', 'company.net' and 'server.company.net' can all be fully qualified domain names, if each one of them points unequivocally to a single IP address. An domain name is not fully qualified, for instance, when it points to a subnet instead of a single IP address. Using "example.com" as a FQDN is technically correct. However, what is 'technically correct' and what Server considers acceptable are not always the same thing....
    I certainly don't want my clients to have problems in the future, and if OS X Server is going to misbehave because of the way I'm setting up my hostname and zone files, I need to know for sure NOW rather than later!

    I'm the "other people" referenced here.
    For general information on DNS, please acquire and skim a copy of Cricket Liu's DNS and BIND book.  It was on its fifth edition when last I checked.  DNS server on OS X Server is the ISC BIND server, which is discussed in that book in some detail.
    If configuring OS X Server in a data center, the OS X Server box probably does not want (nor need) to be running a local DNS server.  (Running local DNS services just means that DNS server will potentially become part of a DNS DDoS, if who can issue queries to the server isn't carefully controlled.)  Use the DC DNS server(s).
    If you want the domain itself to be used as an IP address (eg: example.com), then that's usually an A record, particularly if you're getting email via that domain (and not an MX record going elsewhere).  Some versions of OS X Server have had some issues with setting up this record within Server Admin.app and Server.app.
    The previous issues were likely due to stale DNS translations lurking within the configuration, and caching of that data up to the TTL.  (FWIW, this discussion is related to this thread and this thread.)

  • Writing a binary file

    Hi,
    I have trouble when writing a binary file. Here is what I do:
    I have some VI's collecting various data for a fixed period of time. I put all the data into 1D arrays at a fixed frequency (they all have the same size). Once it is done I merge all the arrays into one 2D array and I write that to a binary file. If I wait about 10 seconds after writing the file and I repeat the whole thing, everything is fine and the timing is correct. If I wait for a shorter period of time (say a sec, and this is the maximum I can wait to have a usable application) then the timing is wrong in the first part of the loop (the time-critical data-acquisition one). Of course, if I don't write the file, everything is fine (I have to wait about 250 msec between two runs, but that's ok). Any advice ?
    I also tried several things like streaming the data to disk during the time-critical period and this works fine only if the file allready exists. If not I experience jitters again. I don't really want to stream the data in real time, but it could work if I can get rid of the jitters. Again, any advice ?
    I'm using LV7.1 and the real time module running on a PC (ETS).
    Another, sort of related, topic: I noticed that when using 2D arrays within time critical loops all the process are slowdown whereas if I use several 1D arrays everything is fine... Any idea why ?
    Thanks,
    Laurent

    Hello,
    File I/O transfer rates during streaming to disk depends on several factors: CPU speed and load, hard drive technology (IDA / Serial ATA / SCSI ...), quality of programming. High jitter is always due to bad programming. File I/O operations are not deterministic. So, file I/O VI's must not be called in the critical task. Data must be saved in the normal priority VI's in order to keep jitter as low as possible. This is the reason why an application in RT is based on RT FIFO to transfer data from the critical loop and the normal priority VI.
    You will find a lot of tutorials detailing the key concepts for RT programming at the link below:
    * Real-Time Module
    http://zone.ni.com/devzone/devzone.nsf/webcategories/C25F8C664230613A862567DF006ABB06
    Moreover, memory allocation in LabVIEW is implicit. You must use large set of data carefully because some function reallocate new buffers for their outputs instead of reusing the input buffers (like the function "build an array"). You will find an example of how we can decrease the memory use with array in LabVIEW in the tutorials linked above.
    If you need more specific advices, you can post a sample code that reproduce the behavior that you does not understand. I will try to look at this and give you my feedback.
    Sincerely.
    Matthieu Gourssies, NIF.

  • Where are the zone files located for BIND??

    I found what should be named.conf in /etc/dns/
    and in this file (which apple calls publicView.conf.apple ....wth?) it links to the zone files:
    +file "db.domain.org.";+
    But db.domain.org isnt in /etc/dns
    so where can I find the zone files?
    Thanks

    look in /var/named/zones.

  • Another DNS Zone Question! :)

    I have several geographic sites all with their own leopard servers (ten or so). Each are open directory masters managing public ip subnets. We do have an external dns server and all of our servers have registered names that are part of the same domain....
    My question is this... when setting up dns on each server, do I need to create zones, or can I just make the dns forward to our external name server. I am worried that having more that one ns authoritative for the same domain will cause problems with our isp dns server? I have one server running just fine without zones... just forwarders ... and all is running smoothly, ical, wiki's, mcx, mobile accounts, etc...
    Looking forward to finding out whether having zones at other locations and authoritative dns servers is a bad thing or not.
    Thanks.

    As long as the external DNS server has all of the info you need, there's no need to set up duplicate zones on your servers; as you note, it could even cause problems if the info got out of sync. In fact, you don't even need to act as a forwarder, you could just turn off DNS service and configure all your computers (servers & clients) to use your ISP's DNS servers.
    In your situation, I see two reasons you might want to run DNS service: in case your internet link goes down (losing access to DNS tends to make it hard to find servers, even if they're on the same LAN), or if the public DNS servers don't have the reverse DNS (IP number -> domain name) entries you need. If you're worried about the first, you could set your servers as secondaries (aka slaves) for the relevant zones, in which case they'll download the zone files from the master and automatically keep in sync. If the second is an issue, you're probably best off bugging your ISP -- since the reverse records are tied to your IP numbers, and those're "owned by" the ISP, they're generally in charge of the reverse DNS no matter who's hosting your forward DNS zones.

  • Different SBA DNS SRV entry for the same dns zone?

    Hello,
    I got here a testlab with one enterprise pool and one sba deployed. The Branch Site got also an DNS Server installed. Both are using the same dns zone "test.com".
    Of course now i got different server for the same SRV Record _sipinternaltls._tcp.test.com - one for autodiscovery in the enterprise pool and one for the sba. Also I want to add the second one as failover srv + the DNS Server in the Enterprise Pool should
    be used as a Forwarder.
    Now I got some issues how to deploy several entries on two different dns server for the same zone.
    1.) If I add manually the same zone + DNS SRV entries on the SBA the dns is somehow not resolving/forwarding the entries on the other dns server in ee to other servers which are not on my SBA dns.
    2.) If I only pinpoint the SRV entries for _sipinternaltls._tcp.test.com (one for sba and failover for ee site) the dns won't resolve the second a record to the enterprise pool.
    What is the Best Practise for DNS SBA? Always point to the enterprise pool and, therefore, no other configuration is needed?
    Regards DrWho

    I played a little bit around. Problem was that I can not add the pinpoint dns srv entries via gui. Aditionally the tutorials did not work as my DNS server for SBA is not on a domain controller. In the end I did this:
    sbafe -> fqdn of my sba
    eefe -> fqdn of my frontend of enterprise pool
    dnscmd . /zoneadd _sipinternaltls._tcp.test.com. /primary /file _sipinternaltls._tcp.test.com.dns
    dnscmd . /recordadd _sipinternaltls._tcp.test.com. @ SRV 0 0 5061 sbafe.test.com.
    dnscmd . /recordadd _sipinternaltls._tcp.test.com. @ SRV 10 0 5061 eefe.test.com.
    dnscmd . /zoneadd sbafe.test.com. /primary /file sbafe.test.com.dns
    dnscmd . /recordadd sip.sbafe.test.com. @ A 192.168.10.220
    dnscmd . /zoneadd eefe.test.com. /primary /file eefe.test.com.dns
    dnscmd . /recordadd sip.eefe.test.com. @ A 192.168.0.40
    Question is if that is a good best proctise or should the dns server within a zone contain the same records (Primary/Backup). The Client will then always hit the FE of the EE Pool first.
    Also its quite a lot of work to setup.

  • Cannot save configuration for zone files

    I'm migrating from 10.3 to 10.4.9. The 10.4.9 system is on a new hard drive so it is a fresh install. I have no problem setting up the BIND config manually from the command line but I like to use Server Admin to start and stop the server. When I noticed I was having problems resolving my servers domain/subdomains, I used Server Admin to take a look at what was going on.
    The problem I seem to be encountering is that Server Admin shows that the zones exist but it does not display any of the zone data in the window to the right of the zone list. I did a quick check on the zone files and found them to be configured correctly. When I tried to edit and then save the configuration using the Server Admin GUI I receive an error telling me that the zone had no name and that the configuration could not be saved.
    Just to test things out a little bit, I dragged the DNS configuration file from the 10.3 config from the Server Admin Applition, rebooted the system back into 10.4, and dropped that configuration back onto the application window. After this process I can see the zone data in the right hand window but when I click the save button I receive the same error.
    My only reference for 10.4 is the Apple Training Series: Mac OS X Server Essentials which describes the Server Admin GUI for the DNS functions and the associated files in a manner that I am familiar with but which are significantly different then what is actually appearing in the Server Admin application for 10.4.9.
    Does anyone know what could possibly be wrong?
    Thanks
    XServe G4   Mac OS X (10.4.8)  

    Unfortunately, there are a number of flaws with the Server Admin DNS tool that absolutely require you to modify the files manual. For instance, you cannot properly set up MX records is the zone you are working on is NOT responsible for the mail server. In other words, you can't set up MX records. Also, the name server text fields are bugged in a way that makes it extremely difficult to add more then one name server. The tool is useless until these problems are fixed.
    Basically, as you said, I used the dns tool to set up the files, then edited them manually in order to get them into a functional state. I just have to make sure that I don't ever use the tool to edit the configuration as it will blow away any changes that were made manually.
    FYI The Server Admin web tool for Apache is also just as annoying, deleting data that has been added manually.

Maybe you are looking for

  • Firm scheduling agreement in MRP

    Hi gurus, We are maintaining scheduling agrements in ME38 manually. system shows firm schedule lines in md04 screen. When we run MRP system does not consider or minus stocks and create planned order equals to the requirements. we need this scenario i

  • My 1st Gen Ipod Touch won't charge while turned on, dies 30 seconds after powering on.

    I own a first gen Ipod Touch. Recently I let it sit until the battery died. When I went to charge it, it wouldn't charge unless I held the charger a specific way. Then, when I discovered the one way it accepted the charger, it started charging. Howev

  • Restarts and Hangs on Surface Pro 3

    Has anyone been experiencing a high number of restarts and hangs on the Surface Pro 3? Over the course of three days I have had 11 BSODs. I scanned the minidmp and it points to ntosknrl.exe. And the event log has the usual unhelpful  "The system has

  • Time machine disk recognition problem

    Having upgraded from Snow leopard to Mountain Lion, time machine could no longer access my time machine backup disk and the finder gave the message that the disk was unrepairable. The files were still visible however. I copied the last Backup Folder

  • Quick Time Player Pro,

    Can anyone tell me how to save a Quick Time Player Pro video clip to a Windows Media Player format? compaq   Windows XP Pro