Just a very quick nugget, finishing up this year of IT.
We needed to change the configured DNS server addresses, on a good bunch of (non-domain joined) servers before heading into 2022. Per usual, I don’t like to do stuff manually, so I took the opportunity to write up a PowerShell script in order to assist us.
I figured this is something anybody might find useful, so I wanted to share the script I ended up creating.
For your convenience, I’m also illustrating how this can be used in combination with ConfigMgr, as this obviously was a requirement for automation purposes.
Happy New Year! 🙂
Find the script over at my GitHub page: PowerShell/Change-DNSServers.ps1 at master · imabdk/PowerShell (github.com)
- Use the script how you see fit. Might need som tweaking to suit your needs. Remember to test thoroughly before using in production!
The use of the script is pretty straightforward. It’s created to accept parameters, so you don’t have to modify the content of the actual script on a need to need basis.
Changing the primary and secondary DNS server addresses, is done by running the script with the -primDNS and -secDNS parameters:
- Change-DNSServers.ps1 -primDNS 22.214.171.124 -secDNS 126.96.36.199
If in need of resetting the DNS server addresses back to default, run the script like so, and set the -primDNS and -secDNS parameters to 0:
- .\Change-DNSServers.ps1 -primDNS 0 -secDNS 0
Using the script with ConfigMgr is easy as well.
Create a package containing the .ps1 file, with a program running following command line:
- powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File .\Change-DNSServers.ps1 -primDNS 188.8.131.52 -secDNS 184.108.40.206
Remember to let the program to run with administrative rights: