Rollout DHCP to clients using Powershell

We have a number of branch offices that currently use fixed IP addresses on Windows 7 clients and we now want to roll DHCP out across those offices.  DHCP servers are a combination of Server 2012 and one Server 2003

The ideal would be that this didn't require a site visit if at all possible.

Does anyone have any suggestions for how to change clients over to DHCP using Powershell remotely.

Are there other ways of achieving this remotely / centrally?

All suggestions gratefully received!


Jon
FriendlyITAsked:
Who is Participating?
 
Joshua GrantomSenior Systems AdministratorCommented:
Something like this may work. You can change the $computers variable to get computer names however you want as long as it returns the computer name. You would also need to run this command with an elevated account that has local admin rights to the remote computers

$computers = Get-Content "C:\computers.txt"
ForEach ($comp in $computers) {
$wmi = Get-WmiObject win32_networkadapterconfiguration -ComputerName $comp -filter "ipenabled ='true'";
$wmi.EnableDHCP();
$wmi.SetDNSServerSearchOrder();
}

Open in new window


To get computers in a certain ou you could use
$computers = Get-ADComputer -SearchBase "OU=mysite,DC=mydomain,DC=com" | Select Name

Open in new window

0
 
FriendlyITAuthor Commented:
Thanks Joshua - that looks like the kind of thing.

Where would you run this script?  On a DC?

Is there any way of telling whether it has been successful?
0
 
Joshua GrantomSenior Systems AdministratorCommented:
You can run this script from anywhere as long as the account running it has local admin credentials to the computers you are wanting to change. You also need to make sure Remote Management and WMI are enabled so you may need to create a group policy for that and apply it first.

Here are instructions for that http://community.spiceworks.com/how_to/17452-group-policy-to-allow-wmi-access-to-remote-machine

To see if it has been successful, you can use another script to get the adapter settings back for each computer

$computers = Get-Content "C:\computers.txt"
ForEach ($comp in $computers) {
Write-Host $comp
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "ipenabled ='true'" -ComputerName $comp | Select ServiceName,Description,DHCPEnabled
}

Open in new window

0
 
FriendlyITAuthor Commented:
I haven't been able to test this yet, but so the question doesn't get flagged as abandoned have accepted this answer which looks like it should work.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.