Enter network settings via powershell

Gustavo Lorenzett 126 Reputation points
2022-10-12T02:03:34.127+00:00

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.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,755 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,396 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. S.Sengupta 15,601 Reputation points MVP
    2022-10-12T03:56:12.307+00:00

    Hope the following article helps:

    Configuring Network Adapter Settings with PowerShell

    0 comments No comments

  2. 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.

    0 comments No comments

  3. Limitless Technology 43,981 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–

    0 comments No comments