Заметки: Выгрузка DNS-записей с помощью Powershell

Недавно для настройки представлений на серверах Bind мне потребовалась выгрузка DNS-записей с серверов Windows. Несмотря на очевидную простоту задачи на деле все оказалось далеко не так просто и быстро.

Пока разбирался каким образом решать задачу и собрал все подводные камни, натолкнулся на множество интересных статей и ресурсов. Обязательно с  вами поделюсь.


Если вам интересны статьи о Powershell, рекомендую обратиться к тегу PowerShell scripting на моем блоге


Выгрузка DNS-записей

Кому сразу нужен код/команды — листайте до пункта Скрипт, а пока разберем саму задачу и теорию.

Задача

Есть сервер Windows с ролью DNS. Есть сервер Bind на Linux с настроенными для различных клиентов представлениями. Нужно с сервера Windows выгрузить (крайне желательно в формате, который знает Bind 1) все записи определенной зоны и засунуть в Bind. Вручную копировать не вариант, записей сотни.

Теория

Выгрузить записи нужной вам зоны (или всех зон враз, почему бы и нет) роли Windows Server DNS можно разными путями. Вот основные.

1. Например записи неинтегрированных в AD зон можно просто скопировать из соответствующих файлов в директории C:\Windows\System32\dns. Для AD-integrated зон такой вариант не подойдет.

2. Вполне можно воспользоваться старой доброй утилитой dnscmd, например:

Где dc01.dns_zone.local и dns_zone.local имена контроллера домена и нужной вам зоны соответственно. Тем не менее, эта утилита уже достаточно стара и использовать её — не самый лучший вариант.

Примечание: стоит отметить, что команда выше не выполняет рекурсию и выведет только записи одного уровня.

3. Самый разумный вариант на текущий момент — использовать Powershell для выгрузки записей. Но этот вариант далеко не самый простой. Почему, рассмотрим ниже.

Скрипт

Для получения всех записей определенной зоны подойдет командлет Get-DnsServerResourceRecord 2. Пример его использования:

Получите подобный вывод (количество записей уменьшено для наглядности):

Многоточие в первой строчке явно намекает, что это сокращение. Этот вариант не подходит, попробуем ограничить выводимые столбцы и указать сортировку:

Уже лучше, но что стало со столбцом RecordData:

Подобный вывод говорит о том, что RecordData — отдельный объект со своими свойствами. Хорошо, проверим что он из себя представляет командой:

Вывод:

Теперь становится понятно, что нам нужно отдельно обрабатывать 3 каждую запись в зависимости от её типа 4. Для этого можно воспользоваться хэш-таблицей 5 6 и командлетом Select-Object 7:

Вот что получилось:

В примере выше я сделал сопоставление только для семи типов записей (потому что для моей задачи больше и не надо), но на деле их будет больше. Мне также было нужно, чтобы каждая запись была определена как fqdn, поэтому к полю HostName нужно добавить суффикс в виде домена. Не лишним также будет выгружать все записи в CSV. Вот как изменится скрипт:

На этом задача решена. Возможно будет логично засунуть этот кусок кода в цикл, если нужно перебирать записи сразу нескольких зон. Это вы уже сделайте сами при необходимости. Успехов!

comments powered by HyperComments
dissertation editing
2022-07-05 15:25:03
<strong>uk dissertation help https://professionaldissertationwriting.org/</strong>
dissertation help free
2022-07-05 17:22:47
<strong>dissertation acknowledgements https://professionaldissertationwriting.com/</strong>
sample dissertation
2022-07-05 21:28:39
<strong>dissertation writers https://helpwithdissertationwritinglondon.com/</strong>
dissertation assistance
2022-07-05 22:20:51
<strong>art dissertation help https://dissertationwritingcenter.com/</strong>
medical dissertation writing services
2022-07-06 02:07:57
<strong>proquest dissertation https://dissertationhelpexpert.com/</strong>
dissertation example
2022-07-06 03:30:23
<strong>uk dissertation writing https://accountingdissertationhelp.com/</strong>
free dissertation help
2022-07-06 10:44:54
<strong>dissertation topics https://writing-a-dissertation.net/</strong>
what is dissertation
2022-07-06 11:28:35
<strong>help dissertation dissertation help https://bestdissertationwritingservice.net/</strong>
dissertation proposal writing help
2022-07-06 15:00:43
<strong>writing the dissertation https://businessdissertationhelp.com/</strong>
write my dissertation for me
2022-07-06 19:00:23
<strong>help writing dissertation https://customdissertationwritinghelp.com/</strong>
writing methodology for dissertation
2022-07-07 00:20:31
<strong>writing dissertation proposal https://dissertationhelpspecialist.com/</strong>
dissertation writing skills
2022-07-07 02:33:03
<strong>write my dissertation for me https://dissertationhelperhub.com/</strong>
doctoral dissertation defense
2022-07-07 06:29:26
<strong>writing a dissertation literature review https://customthesiswritingservices.com/</strong>
best online casino
2022-07-25 19:44:48
<strong>online casino bitcoin https://download-casino-slots.com/</strong>
bravado online casino
2022-07-25 22:43:13
<strong>casino online free play https://firstonlinecasino.org/</strong>
real online casino usa
2022-07-26 02:08:23
<strong>online casino no deposit required https://newlasvegascasinos.com/</strong>
rivers online casino
2022-07-26 05:45:32
<strong>virgin casino online https://trust-online-casino.com/</strong>
online casino with free signup bonus real money usa
2022-07-26 06:50:20
<strong>resorts world casino online https://onlinecasinosdirectory.org/</strong>
online casino arizona
2022-07-26 11:00:51
<strong>online casino deposit bonus https://9lineslotscasino.com/</strong>
paradise online casino
2022-07-26 11:53:26
<strong>cesar online casino https://free-online-casinos.net/</strong>
online casino spielen
2022-07-26 16:44:21
<strong>caesar casino online https://cybertimeonlinecasino.com/</strong>
online vegas casino
2022-07-26 19:57:37
<strong>fast payout online casino https://1freeslotscasino.com/</strong>
casino online gambling
2022-07-26 21:53:41
<strong>888 casino online support https://vrgamescasino.com/</strong>
baccarat online casino
2022-07-27 00:33:10
<strong>online casino hrvatska https://casino-online-roulette.com/</strong>
resorts online casino bonus codes
2022-07-27 04:34:47
<strong>hollywood online casino https://casino-online-jackpot.com/</strong>
casino online dinero real usa
2022-07-27 06:56:01
<strong>live casino online free https://onlineplayerscasino.com/</strong>
casino online free play
2022-07-27 11:30:59
<strong>mgm online casino pa https://all-online-casino-games.com/</strong>
online casino free spins no deposit
2022-07-27 15:26:03
<strong>gun lake online casino https://casino8online.com/</strong>
vpn server buy
2022-08-07 14:24:04
<strong>best vpn for gaming free https://freevpnconnection.com/</strong>
free vpn reddit
2022-08-07 17:23:17
<strong>free unlimited vpn https://shiva-vpn.com/</strong>
free vpn server address
2022-08-07 20:36:51
<strong>avast secure vpn https://freehostingvpn.com/</strong>
netflix vpn free
2022-08-07 22:32:44
<strong>vpn for firestick free https://ippowervpn.net/</strong>
free vpn for windows 7
2022-08-08 01:36:17
<strong>which vpn to buy https://imfreevpn.net/</strong>
get us vpn service
2022-08-08 02:15:21
<strong>best torrent vpn https://superfreevpn.net/</strong>
should i buy vpn anonymously
2022-08-08 06:00:30
<strong>hola free vpn proxy https://free-vpn-proxy.com/</strong>
gay conservative dating ap
2022-08-23 15:04:26
<strong>gay dating cites https://gay-singles-dating.com/</strong>
torrington ct gay dating
2022-08-23 17:01:18
<strong>which gay dating app has most members https://gayedating.com/</strong>
gay dating documentary youtube
2022-08-23 18:55:27
<strong>gay dating in louisiana https://datinggayservices.com/</strong>
single chat sites
2022-08-24 12:26:36
<strong>meet online service https://freephotodating.com/</strong>
singles dating
2022-08-24 15:36:32
<strong>tinder login https://onlinedatingbabes.com/</strong>
sites adult
2022-08-24 16:54:03
<strong>local free dating sites https://adult-singles-online-dating.com/</strong>
free dating sites for single men and women
2022-08-24 19:40:39
<strong>dating services online https://adult-classifieds-online-dating.com/</strong>
singles in women
2022-08-25 01:10:43
<strong>single web site https://speedatingwebsites.com/</strong>
best online dating sites
2022-08-25 02:17:17
<strong>100% free dating site in europe https://datingpersonalsonline.com/</strong>
dating services
2022-08-25 06:01:02
<strong>dating free online https://wowdatingsites.com/</strong>
dating chat site
2022-08-25 11:40:00
<strong>dating sites for singles https://virtual-online-dating-service.com/</strong>
online datings
2022-08-25 16:38:52
<strong>dating simulator https://onlinedatingservicesecrets.com/</strong>
orion stars online casino
2022-08-30 09:15:37
<strong>iowa online casino https://onlinecasinos4me.com/</strong>
best online casino in canada
2022-08-30 12:18:19
<strong>rivers casino online https://online2casino.com/</strong>
online casino welcome bonus
2022-08-30 19:42:45
<strong>online sweepstakes casino real money https://casinosonlinex.com/</strong>
gay tranny webcam chat
2022-09-03 01:47:33
<strong>best gay webcam chat https://newgaychat.com/</strong>
free asain chat lines gay
2022-09-03 04:35:42
<strong>gay phone chat lines caribbean https://gaychatcams.net/</strong>
gay chub chat
2022-09-03 12:51:07
<strong>gay incet chat https://gaychatspots.com/</strong>
gay live chat
2022-09-03 16:37:43
<strong>free gay sex chat apps https://gay-live-chat.net/</strong>
wed chat gay free
2022-09-03 21:11:07
<strong>free chat with men - live gay cams, free gay webcams at chaturbate https://chatcongays.com/</strong>
gay chat rouetee
2022-09-04 01:45:41
<strong>free gay chat by zip code 53214 https://gayphillychat.com/</strong>
free gay bi chat lines in seattle wa
2022-09-04 05:44:00
<strong>gay chat rooms on aol town square https://gaychatnorules.com/</strong>
chat for free gay webcam
2022-09-04 13:27:14
<strong>free iowa gay chat rooms https://gaymusclechatrooms.com/</strong>
transcripts of first time gay chat
2022-09-04 16:14:24
<strong>gay college chat rooms no cam needed https://free-gay-sex-chat.com/</strong>
gay male video chat free
2022-09-04 21:03:13
<strong>gay men chat https://gayinteracialchat.com/</strong>
zoom chat gay
2022-10-20 16:36:51
<strong>gay pnp chat free https://gaymanchatrooms.com/</strong>
help with writing paper
2022-10-20 18:01:07
<strong>help writing my paper https://term-paper-help.org/</strong>
custom paper writing service
2022-10-20 19:13:57
<strong>pay someone to do my paper https://sociologypapershelp.com/</strong>
order papers online
2022-10-20 20:26:38
<strong>buy papers online https://uktermpaperwriters.com/</strong>
help paper
2022-10-20 23:54:43
<strong>buy college paper online https://writepapersformoney.com/</strong>
best college paper writing service
2022-10-21 01:37:51
<strong>buying college papers https://write-my-paper-for-me.org/</strong>
paper writers
2022-10-21 02:01:52
<strong>buy cheap paper https://doyourpapersonline.com/</strong>
papers help
2022-10-21 04:00:42
<strong>write my paper https://top100custompapernapkins.com/</strong>
professional paper writing services
2022-10-21 05:43:03
<strong>write my college paper https://researchpaperswriting.org/</strong>
do my college paper for me
2022-10-21 07:57:04
<strong>help with writing papers https://writingpaperservice.net/</strong>
help me write a paper
2022-10-21 09:05:29
<strong>help with writing a paper for college https://buyessaypaperz.com/</strong>
pay to write papers
2022-10-21 10:50:43
<strong>pay to do my paper https://mypaperwritinghelp.com/</strong>
writing paper help
2022-10-21 13:03:00
<strong>pay for paper https://essaybuypaper.com/</strong>
help writing paper
2022-10-21 14:36:42
<strong>best write my paper website https://papercranewritingservices.com/</strong>
customized writing paper
2022-10-21 16:17:04
<strong>finished custom writing paper https://premiumpapershelp.com/</strong>
where to buy papers
2022-10-21 17:14:51
<strong>college papers help https://ypaywallpapers.com/</strong>
buy thesis paper
2022-10-21 18:11:53
<strong>professional paper writing services https://studentpaperhelp.com/</strong>
2latticed
2023-01-26 03:47:33
<strong>3sanitation</strong>
coursework help uk
2023-02-05 18:00:15
<strong>coursework writing service https://writingacoursework.com/</strong>
coursework psychology
2023-02-05 19:34:35
<strong>coursework help uk https://mycourseworkhelp.net/</strong>
design coursework
2023-02-05 20:25:37
<strong>coursework resources https://courseworkdownloads.com/</strong>
coursework writer
2023-02-05 21:47:18
<strong>do my coursework for me https://courseworkinfotest.com/</strong>
coursework website
2023-02-05 22:54:47
<strong>coursework paper https://coursework-expert.com/</strong>
differential equations coursework
2023-02-06 00:27:34
<strong>coursework masters https://teachingcoursework.com/</strong>
creative writing coursework ideas
2023-02-06 01:25:52
<strong>coursework paper https://buycoursework.org/</strong>
design technology coursework
2023-02-06 02:22:30
<strong>design coursework https://courseworkdomau.com/</strong>
senior dating sites
2023-02-08 13:09:57
<strong>best datings sites https://freewebdating.net/</strong>
completely free dating sites
2023-02-08 14:05:15
<strong>indian dating https://jewish-dating-online.net/</strong>
online dating personals
2023-02-08 16:03:03
<strong>datingnow life https://free-dating-sites-free-personals.com/</strong>
asian girl single
2023-02-08 17:20:55
<strong>singles near you https://sexanddatingonline.com/</strong>
top online dating
2023-02-08 20:08:45
<strong>dating top sites https://onlinedatingsuccessguide.com/</strong>
good free dating sites
2023-02-08 21:45:18
<strong>date online https://onlinedatinghunks.com/</strong>
american singles
2023-02-08 23:14:13
<strong>meet european singles in usa https://datingwebsiteshopper.com/</strong>
sating websites
2023-02-09 00:00:20
<strong>dating https://allaboutdatingsites.com/</strong>
best dating
2023-02-09 01:27:53
<strong>chat with singles https://freedatinglive.com/</strong>
Яндекс.Метрика