PowerShell and Network Connections

PowerShell is a powerful tool for managing network settings. With many cmdlets, you can list network adapters, check connection statuses, configure IP addresses, and more. We'll look at the basics.

Gathering Network Information

The Get-NetIPAddress cmdlet allows you to retrieve IP address information and other IP configuration details assigned to a computer's network interfaces.

Get-NetIPAddress

Other commands that can be used are legacy tools from CMD that are still in use.

IPConfig

Short for "Internet Protocol Configuration," this command is used to display IP configuration information for network connections. It lists IP addresses, subnet masks, default gateways, and other network configuration details assigned to the computer's current network connections.

PS C:\> ipconfig
Windows IP Configuration

Ethernet adapter Ethernet Instance 0:   
    Connection-specific DNS Suffix  . :   
    Site-local IPv6 Address . . . . . : fec0::e9d4:ba34:6516:c0c1%1   
    Link-local IPv6 Address . . . . . : fe80::e9d4:ba34:6516:c0c1%6   
    IPv4 Address. . . . . . . . . . . : 10.0.2.15   
    Subnet Mask . . . . . . . . . . . : 255.255.255.0   
    Default Gateway . . . . . . . . . : fe80::2%6                                       
                                        10.0.2.2

Netstat

A tool used to display network connections for the TCP/IP protocol, routing tables, and network interface statistics.

Nslookup

A tool used to query the DNS (Domain Name System) to obtain domain name or IP address mapping details. It is used to find the IP address corresponding to a given domain name.

ARP

Short for Address Resolution Protocol, this protocol is used to map IP addresses to physical MAC addresses in a network. The ARP command manages the ARP cache and lists the entries in this cache.

Testing Connections

The Test-NetConnection cmdlet is used to test the status of a network connection by pinging a computer.

Downloading Files

Invoke-WebRequest is a cmdlet used to interact with web pages and web services. It allows you to send HTTP/HTTPS requests and receive data or perform actions on these web resources.

To download a file, you can use the command as follows:

Here, the -Uri parameter specifies the web address and the -OutFilep arameter specifies the file name to save the file as.

Last updated