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
FriendlyITInfrastructure TeamAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FriendlyITInfrastructure TeamAuthor 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
FriendlyITInfrastructure TeamAuthor 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DHCP

From novice to tech pro — start learning today.