Set from Static to DHCP

Roger Roger 4,951 Reputation points
2021-10-27T01:22:41.347+00:00

Hi All

i have few windows 10 machines in a csv file. i want to set the ip from static to DHCP on these machines, how do i do it from powershell. experts guide me. my csv file is in below format

vm1.contoso.com
vm2.contoso.com
vm3.contoso.com

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,453 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,370 questions
Windows Server 2012
Windows Server 2012
A Microsoft server operating system that supports enterprise-level management, data storage, applications, and communications.
1,528 questions
Windows DHCP
Windows DHCP
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.DHCP: Dynamic Host Configuration Protocol (DHCP). A communications protocol that lets network administrators manage centrally and automate the assignment of Internet Protocol (IP) addresses in an organization's network.
1,021 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,362 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 44,776 Reputation points
    2021-10-27T18:52:42.747+00:00

    Is your DHCP also going to be provisioning the gateway address? If it is you'll need to do two things:

    Set-NetIPInterface -InterfaceAlias 'Ethernet 1' -Dhcp Enabled
    

    and:

    Get-NetIPAddress -InterfaceAlias 'Ethernet 1' | Remove-NetRoute
    

    Also, knowing just the name of the machine isn't enough. You'll also have to provide the name of the NIC you want to change, and that may be different on each machine.

    When you change the IP address you're going to be disconnected, so build that problem into the script you write.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Gary Reynolds 9,391 Reputation points
    2021-10-27T03:49:41.5+00:00

    Hi,

    Have a look at this page which has details of the add-dhcpserverv4reservation command, which includes some sample scripts on how to import from a file.

    https://learn.microsoft.com/en-us/powershell/module/dhcpserver/add-dhcpserverv4reservation?view=windowsserver2019-ps

    Gary.

    0 comments No comments