Setting DNS for Windows Servers Using PowerShell

Setting DNS for Windows servers is straightforward using PowerShell. Utilizing Get-WMIObject Win32_NetworkAdapterConfiguration against a list of servers from a text file in a loop is the best way to handle a bulk dns change to your servers. I was prompted to share my PowerShell script after reading a post from Mike Tabor on his blog at MikeTabor.com titled How to update VMware Windows VM’s DNS using PowerCLI .

Mike Tabor goes through his process of taking an old script he found and updated it to more modern PowerCLI script. His script is very useful in that you can change the IP address in addition to setting dns for Windows servers in your VMware environment. He credits Jase McCarty who created the original script and helped Mike update it. I encourage you to go check it out.

Person's hand typing on a MacBook Pro with code on the screen
Scripting time

Set-ServersDNS

Here is my purely PowerShell script that I have been using for the past few years to make dns changes. It does not update IP addresses but does allow for changes to dns settings. Using a foreach loop with all the necessary dns settings through Get-WMIObject makes for a simplified script. But just because it is simplified doesn’t mean you can’t do mass amounts of damage to your environment. I always test against a few individual test servers just to make sure before I send this against all my Windows servers.

It does work on both physical and virtual Windows computers. Unfortunately we still have a few Windows physical servers so I will still utilize this script when setting dns for Windows servers. However, when I need to make a mass IP and dns change to virtual machine servers I will utilize Mike Tabor’s script. I expect that soon my environment will not have any physical Windows servers. All virtual is the goal!

Caution: Like all code you download from the internet, please understand and modify the code accordingly to prevent unforeseen production problems.  Also known as career-altering events. 

More From My Site

Schannel Set-Crypto PowerCLI Script

Backup VDS PowerCLI Script

vami_config_net To Change VCSA Hostname

Deleting Orphaned Virtual Desktops In VMware View

PowerShell SSL Certificate Script

Advertisements

Unleash your formidable comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.