How to enable dhcp and configure dns on remote machines

There may come a time when a group of machines with static ip's need to be set to DHCP, this could be a time consuming pain if there is many of them and worse still if the machines are at a remote location. This script will force DHCP on the remote machine and tell it to get it's DNS settings from the DHCP server

Make a list

First we need our list of computers, this can be from a csv or in this example imported from AD


Start a foreach loop

Now we run the list of machines through a foreach loop

foreach ($comp in $computers) {

Find the network card

This line will find the network cards of the remote machine but only the cards whcih are currently active

$Netcard = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $ | where{$_.IPEnabled -eq TRUE}


This line simply tells the card to use the DHCP settings given by the DHCP server



Now we apply DHCP to all the active cards, you may not want to apply DHCP to all the cards but without knowing more about the specific card it is going to be tricky to nail just one card in the machine.

$netcard | ForEach-Object -Process {$_.EnableDHCP()} }

Cut - Paste - Edit

This is the full script, in this example I have also included a small foreach loop which will check that all the network cards are not set to DHCP











// Collect comments ''