Networking With Windows PowerShell

Get-NetIPConfiguration

To get IP Address, Default Gateway, and Subnet Mask for Network Adapters in a computer, we use Get-NetIPConfiguration.

Example

PS C:\> Get-NetIPConfiguration

Windows PowerShell

Test-Connection

To check the network connectivity to any host or a domain, use “Test-Connection”.

Example

PS C:\> Test-NetConnection www.twitter.com

( Here, I am trying to test the network connectivity to Twitter web site. As you can see in the results, PingSuceeded is TRUE, which means the connection is active).

Example

Windows PowerShell

D
etailed Information

To get detailed information on your Ping Status, use -InformationLevel parameter.

Example

PS C:\> Test-NetConnection -ComputerName www.twiiter.com -InformationLevel Detailed

Windows PowerShell

R
esolve-DNSName

Use Resolve-DNSName to find IP address of a given domain.

Example

PS C:\> Resolve-DNSName www.c-sharpcorner.com

Windows PowerShell

TraceRoute

To list all the hops between your computer machine to a host, use -TraceRoute parameter.

Example

PS C:\> Test-Connection -ComputerName www.microsoft.com -TraceRoute

Windows PowerShell

List IP Address for a Computer

To list all the IP addresses that are in use on the local computer, use Win32_NetworkAdapterConfiguration class.

Example

PS C:\> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnable=True -ComputerName IND-DNS1

(Here, IND-DNS1 is the name of my computer)

Windows PowerShell

Ping a Computer

Win32_PingStatus is a Windows Management Instrumentation (WMI) class, used to ping a computer.

Example

PS C:\> Get-WmiObject -Class Win32_PingStatus -Filter “Address=‘127.0.01’” -ComputerName IND-DNS1

Windows PowerShell

(Tip: Include Address, ResponseTime and StatusCode properties in Format-Table to get better summary Information of display )

PS C:\> Get-WmiObject -Class Win32_PingStatus -Filter “Address=‘127.0.01’” -ComputerName IND-DNS1 | FT -property Address, ResponseTime, StatusCode

Windows PowerShell

Retrieve Network Adapter Properties

To get Network Adapter properties of a computer, use Win32_NetworkAdapter class.

Example

PS C:\ > Get-WmiObject -Class Win32_NetworkAdapter -ComputerName IND-DNS1

Windows PowerShell

Assign DNS Domain

To Assign a DNS Domain to a computer use, SetDomain method

Example

PS C:\> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=True -ComputerName IND-DNS1 | ForEach-Object -Process($_.SetDomain(“rakeshwinserv2016.com”)}

Windows PowerShell

Find DHCP Enabled Network Adapters

To Find all DHCP Enabled Network Adapters on a computer machine, use Win32_NetworkAdapterConfiguration class and filter using “DHCPEnabled=True”

Example

PS C:\> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -filter “DHCPEnabled=True” -ComputerName IND-DNS1

Windows PowerShell

Enable DHCP on Each Adapter

To enable DHCP on each Network Adapter, use EnableDHCP method.

Example

PS C:\> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -filter “DHCPEnabled=True” -ComputerName IND-DNS1 | ForEach-Object -process {($_.EnableDHCP()}

Windows PowerShell

Release DHCP Lease for a specific Network Adapter

Use ReleaseDHCPLease method of NetworkAdapterConfiguration to Release DHCP for a network adapter on a subnet.

Example

PS C:\> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter “IPEnabled=true and DHCP Enabled=true” -ComputerName IND-DNS1 | Where-Object -FilterScript {$_.DHCPServer -contains “10.0.2.15”} | ForEach-Object -Process {$_.ReleaseDHCPLease()}

Windows PowerShell

Renew DHCP Lease for a specific Network Adapter

Use RenewDHCPLease method of NetworkAdapterConfiguration to Release DHCP for a network adapter on a subnet.

Example

PS C:\> Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter “IPEnabled=true and DHCP Enabled=true” -ComputerName IND-DNS1 | Where-Object -FilterScript {$_.DHCPServer -contains “10.0.2.15”} | ForEach-Object -Process {$_.RenewDHCPLease()}

Windows PowerShell

Create Network Share

Create a share to share a folder. You can use net share to create a network share.

Example

PS C:\> net share tempshare=c:\Rakesh /users:25 / remark:”Example of tempshare share”

Windows PowerShell

Once, you create this network share, you can verify this using Computer Management.

Verify Network Share

Windows PowerShell

R
emove Network Share

You can delete a network share using net share.

Example

PS C:\ > net share tempshare /delete

Windows PowerShell

Up Next
    Ebook Download
    View all
    Learn
    View all