Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Switching between DHCP & Static IP in Powershell

$
0
0

I am looking to run a Power Shell script that does the following:

1. Determine the active NIC and import it. Currently I am able to find the active NICs with this command -

Get-WmiObject -Class win32_NetworkAdapter -ComputerName LocalHost -Filter "NetworkConnectionStatus = 2" | Format-Table Name, NetEnabled, NetConnectionStatus, DeviceID -AutoSize

2. Ask the user which interface to use - if more than one active interface

3. Ask the user if they want a Static (If Static, have the option to enter the IP, Subnet Mask, & Default Gateway or use presets) or Dynamic IP then run one of the following commands

$NIC.EnableDHCP()

or

$NIC.EnableStatic("192.168.1.2","255.255.255.0")

If switching from DHCP to Static, it should first release the IP.

Thanks in advance,

Pat


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>