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-NetIPAddressOther 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.2Netstat
A tool used to display network connections for the TCP/IP protocol, routing tables, and network interface statistics.
PS C:\> netstat
Active Connections
Proto Local Address Foreign Address State
TCP 10.0.2.15:62553 SRV2019:domain TIME_WAIT
TCP [::1]:389 SRV2019:49531 ESTABLISHED
TCP [::1]:389 SRV2019:49551 ESTABLISHED
TCP [::1]:389 SRV2019:49558 ESTABLISHED
TCP [::1]:389 SRV2019:49677 ESTABLISHED
TCP [::1]:389 SRV2019:49678 ESTABLISHED
TCP [::1]:389 SRV2019:49683 ESTABLISHED
TCP [::1]:49531 SRV2019:ldap ESTABLISHED
TCP [::1]:49551 SRV2019:ldap ESTABLISHED
...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.
PS C:\> nslookup example.com
Server: localhost
Address: ::1
Non-authoritative answer:
Name: example.com
Addresses: 2606:2800:220:1:248:1893:25c8:1946
93.184.216.34ARP
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.
PS C:\> arp -a
Interface: 10.0.2.15 --- 0x6
Internet Address Physical Address Type
10.0.2.2 52-55-0a-00-02-02 dynamic
10.0.2.3 52-55-0a-00-02-03 dynamic
10.0.2.255 ff-ff-ff-ff-ff-ff static
224.0.0.22 01-00-5e-00-00-16 static
224.0.0.251 01-00-5e-00-00-fb static
224.0.0.252 01-00-5e-00-00-fc static
239.255.255.250 01-00-5e-7f-ff-fa static
255.255.255.255 ff-ff-ff-ff-ff-ff staticTesting Connections
The Test-NetConnection cmdlet is used to test the status of a network connection by pinging a computer.
Test-NetConnectionDownloading 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:
Invoke-WebRequest -Uri "https://upload.wikimedia.org/wikipedia/commons/a/af/PowerShell_Core_6.0_icon.png" -OutFile "powershell.png"Here, the -Uri parameter specifies the web address and the -OutFilep arameter specifies the file name to save the file as.
Last updated