PowerShell set DHCP to automatically obtain IP addresses, PowerShell can easily set up the local computer to enable DHCP to dynamically obtain IP addresses, which requires a WMI extension. This article describes the detailed scripting procedures.
PowerShell set DHCP to automatically obtain IP addresses
PowerShell makes it easy to set up the local computer to enable DHCP to dynamically obtain IP addresses, which requires a WMI extension. This article describes the detailed scripting procedures.
The first step is to use Get-wmiobject to obtain the specified network adapter configuration object
Copy Code code as follows:
$NETADP = Gwmi Win32_NetworkAdapterConfiguration |? {$_.index-eq 7}
Description
1, Gwmi is Get-wmiobject this cmdlet alias, for the sake of convenience, direct use of GWMI.
2. Win32_NetworkAdapterConfiguration is the object of network card configuration in WMI, it can be used to manipulate the configuration of network card.
3,? {$_.index-eq 7} filters the NIC with an ordinal number of 7 from all the acquired network card objects. This place Hongo to remind everybody to notice, you can not after the pipeline of this condition content, the program will output all the network card information, and then you choose you need to modify the value of the network card information.
4, for each network adapter configuration object, contains the content as follows.
Copy Code code as follows:
Dhcpenabled:true
IPAddress:
DefaultIPGateway:
DNSDomain:
servicename:k57nd60a
Description:broadcom NetLink (TM) Gigabit Ethernet
Index:7
The second step is to view the current DHCP configuration of the selected network card
Copy Code code as follows:
PS c:\users\zhanghong> $NETADP. dhcpenabled
True
The output value of TRUE indicates that DHCP is currently enabled. Of course, if the output will be false to indicate that DHCP is not enabled, a static IP configuration is used.
Step three, open and complete DHCP automatic get IP
Open command:
Copy Code code as follows:
When you turn off DHCP, you must configure a static IP address:
Copy Code code as follows:
$NETADP. EnableStatic ("192.168.0.2", "255.255.255.0")
OK, about using PowerShell to configure DHCP or static IP addresses, so, I hope to help you.