Hope the following article helps:
Enter network settings via powershell
Guys, I need help with a script. I need to configure the IP address + netmask + gateway + DNS, but the user must enter this information.
Which powershell command can I use in this case?
Example:
$condition = Read-Host "Enter Y to change Computer IP or N to not change."
if ( $condition -eq "Y")
{
$ip = Read-Host "IP."
$masc = Read-Host "Mask."
$gat = Read-Host "Gateway."
$dns1 = Read-Host "DNS."
$dns2 = Read-Host "DNS2."
}
I thank.
3 answers
Sort by: Most helpful
-
-
Gustavo Lorenzett 126 Reputation points
2022-10-12T13:15:15.067+00:00 The content is very good, but it wouldn't quite be what you'd be looking for. My goal is for the user to interact with the configuration.
-
Limitless Technology 44,516 Reputation points
2022-10-13T07:58:29.567+00:00 Hello there,
You can display detailed IP configuration data for each network adapter by using this script
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName
This will give you a list of DNS Servers
Get-WmiObject Win32_NetworkAdapterConfiguration -computername . | select name, DNSServerSearchOrder
The following Script will change your Enabled Network cards to be Dynamic
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration `
| where{$_.IPEnabled -eq “TRUE”}
Foreach($NIC in $NICs) {
$NIC.EnableDHCP()
$NIC.SetDNSServerSearchOrder()
}
IPConfig /all------------------------------------------------------------------------------------------------------------------------------------------------------------
--If the reply is helpful, please Upvote and Accept it as an answer–