en:powershell:dns
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:powershell:dns [2021/04/05 13:52] – created lonclegr | en:powershell:dns [2021/04/12 20:26] (current) – lonclegr | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | FIXME **This page is not fully translated, yet. Please help completing the translation.**\\ //(remove this paragraph once the translation is finished)// | ||
| - | |||
| ====== DNS ====== | ====== DNS ====== | ||
| - | Here I want to show how huge is the difference between a string and an object. | + | Here I want to show how huge the difference |
| ===== Initial request ===== | ===== Initial request ===== | ||
| + | Let's suppose you have to perform a lot of DNS modifications because a service provider of yours has changed IP server. Since you are wise, you are going to follow the rule: Trust but verify. | ||
| + | - Check input: maybe some mistakes in the request | ||
| + | - Provide a preCheck report to the requester | ||
| - | Supposons que vous ayez à faire énormément de modifications DNS à cause d'un fournisseur qui change de serveur. On vous donne une liste d' | + | This is the example we are going to deal with: |
| - | + | ||
| - | - Vérifier les données fournies par le demandeur: la confiance n' | + | |
| - | - Fournir le rapport preCheck à votre commanditaire. | + | |
| - | + | ||
| - | + | ||
| - | Pour l' | + | |
| <csv> | <csv> | ||
| Line 25: | Line 20: | ||
| </ | </ | ||
| - | ===== Le piège | + | ===== Trap to avoid ===== |
| - | Si on décide d'aborder le défi en utilisant | + | Sysadmins are used to execute nslookup command to query DNS servers. Let's put it into a powershell |
| <file powershell dns_v1.ps1 > | <file powershell dns_v1.ps1 > | ||
| Line 35: | Line 30: | ||
| </ | </ | ||
| - | On obtient des choses horribles. | + | Output is a nightmare. |
| < | < | ||
| Line 53: | Line 48: | ||
| </ | </ | ||
| - | Cela pose les problèmes suivants: | + | Here is an issues list: |
| - | - Les résultats s' | + | |
| - | - nslookup n'est pas une commande Powershell alors on n' | + | |
| - | - Impossible d' | + | |
| - | ===== Le bon outil ===== | + | - Quite difficult to parse results |
| + | - nslookup is not a built-in Powershell command, as a result we don't get answer as kind of DNS object | ||
| + | - Really hard to create preCheck output file | ||
| - | Nous allons donc utiliser la commande DNS PowerShell: Resolve-Dns | + | ===== the right tool for the right problem ===== |
| + | |||
| + | Recent versions of PowerShell | ||
| <file powershell dns_v2.ps1 > | <file powershell dns_v2.ps1 > | ||
| Line 68: | Line 64: | ||
| </ | </ | ||
| - | Cette fois-ci on obtient quelque chose de beaucoup plus sympa avec des objets que nous allons pouvoir manipuler. | + | Now script outputs something we can easily manage and export. |
| < | < | ||
| Line 84: | Line 80: | ||
| </ | </ | ||
| - | On obtient toujours une exception | + | We still raise an exception |
| <file powershell dns_v3.ps1> | <file powershell dns_v3.ps1> | ||
| Line 100: | Line 95: | ||
| </ | </ | ||
| - | On obtient des objets que nous allons pouvoir manipuler et exporter. | + | When the DNS A record exists, we get an object from Microsoft.DnsClient.Commands.DnsRecord_A class. Otherwise we catch the exception properly. |
| < | < | ||
| Line 115: | Line 111: | ||
| </ | </ | ||
| - | ===== Script final ===== | + | ===== Final script |
| - | On se rappelle ce que l'on souhaite: prendre tous les enregistrements | + | Reminder: we want to verify if all DNS A records provided by the requester are correct. |
| <file powershell dns_final.ps1> | <file powershell dns_final.ps1> | ||
| Line 145: | Line 141: | ||
| </ | </ | ||
| - | Le résultat permet de mettre en valeur un domaine qui n'a pas d' | + | From the result we can easily identify names without DNS A records. Mission accomplished :-) |
| <csv> | <csv> | ||
en/powershell/dns.1617645176.txt.gz · Last modified: by lonclegr
