Warning: mysqli_result::fetch_assoc() expects exactly 0 parameters, 1 given in /var/www/powershellpower.com/public_html/page_parts/page.php on line 78

Warning: Use of undefined constant page_id - assumed 'page_id' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 92

Warning: Use of undefined constant synopsis - assumed 'synopsis' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 93

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

7
Warning: mysqli_result::fetch_assoc() expects exactly 0 parameters, 1 given in /var/www/powershellpower.com/public_html/page_parts/page.php on line 156

Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
Make a list

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


#Importthecomputerlist#
$computers=Get-ADComputer-Filter*



Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
Start a foreach loop

Now we run the list of machines through a foreach loop


foreach ($comp in $computers) {



Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
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 $comp.name | where{$_.IPEnabled -eq TRUE}



Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
Set DNS

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


$netcard.SetDNSServerSearchOrder()



Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
Set DHCP

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()} }



Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /var/www/powershellpower.com/public_html/page_parts/page.php on line 185
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


#Importthecomputerlist#
$computers=Get-ADComputer-Filter*



#ChangetoDHCPandAUTODNS

foreach($compin$computers){

$Netcard=Get-WMIObjectWin32_NetworkAdapterConfiguration-computername$comp.name|where{$_.IPEnabled-eqTRUE}

$netcard.SetDNSServerSearchOrder()

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







#Checktheconfigonallchangedmachines

foreach($compin$computers){

echo$comp.name
Get-WMIObjectWin32_NetworkAdapterConfiguration-computername$mc.ip|where{$_.IPEnabled-eqTRUE}|where{$_.DHCPEnabled-eqTRUE}|`
selectDHCPEnabled,DNSDomain

}


Comments

Notice: Undefined variable: commentno in /var/www/powershellpower.com/public_html/page_parts/page.php on line 335
// Collect comments ''
Fatal error: Uncaught Error: Call to a member function fetch_assoc() on bool in /var/www/powershellpower.com/public_html/page_parts/comments.php:9 Stack trace: #0 /var/www/powershellpower.com/public_html/page_parts/page.php(343): include() #1 /var/www/powershellpower.com/public_html/pages/how_to_enable_dhcp_and_configure_dns_on_remote_machines.php(2): include('/var/www/powers...') #2 {main} thrown in /var/www/powershellpower.com/public_html/page_parts/comments.php on line 9