Forum Discussion
DNS block list
- Aug 26, 2021
You may automate it using PowerShell, you may add the list into a Excel document and save it with CSV format and then use Import-Csv command to import it as a list in the PowerShell, take a look at https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/import-csv?view=powershell-7.1
Then use function like Add-DnsServerPrimaryZone in a loop or and it will read each record and add it to the DNS. Take a look at https://docs.microsoft.com/en-us/powershell/module/dnsserver/add-dnsserverprimaryzone?view=windowsserver2019-ps
Try to create a script for one record and then if it works as you expected then use the list.
- Reza_AmeriAug 26, 2021Silver Contributor
You may automate it using PowerShell, you may add the list into a Excel document and save it with CSV format and then use Import-Csv command to import it as a list in the PowerShell, take a look at https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/import-csv?view=powershell-7.1
Then use function like Add-DnsServerPrimaryZone in a loop or and it will read each record and add it to the DNS. Take a look at https://docs.microsoft.com/en-us/powershell/module/dnsserver/add-dnsserverprimaryzone?view=windowsserver2019-ps
Try to create a script for one record and then if it works as you expected then use the list.
- alescanAug 27, 2021Brass Contributor
This is not a bad idea, but instead of make and import csv, is better to read the txt file directly with:
Get-Content .\file.txt | ForEach-Object {
Add-DnsServerPrimaryZone ....
}- Reza_AmeriAug 27, 2021Silver ContributorTrue, that's work too , however from experience I find out the CSV format is more reliable for large set of data but like you said reading from text file works too.