This document provides an introduction to using PowerShell for network configuration and troubleshooting. It discusses how PowerShell can be used to view and manage network settings like IP addresses, interfaces, routing tables, DNS settings, and services. It provides examples of PowerShell cmdlets for tasks like displaying IP configurations, enabling and disabling interfaces, testing connectivity, resolving names, viewing the DNS cache, and checking and restarting services.
2. Introduction
• PowerShell is a command-line shell and scripting language that seeks to help admins configure systems and automate
tasks.
• The object-oriented technology is built on Microsoft's .NET framework.
• As such, it lets IT personnel work with objects in contrast with text-based shells.
• Windows PowerShell has revolutionized the Windows command line.
• From configuration management to software installation to scripting, PowerShell is one of the most
powerful tools in any Windows administrator's toolbox.
• And PowerShell is also useful for managing Windows network settings and services.
3. What is PowerShell used for?
• PowerShell, in its role as command-line shell, serves as the replacement for Microsoft's Command
Prompt, which goes back to the days of DOS.
• Microsoft made PowerShell the default command-line interface (CLI) for Windows 10 as of build
14791. Most users first interact with PowerShell in its command-line capacity.
• The key use case for PowerShell is automating various administrative activities.
• Examples include navigating registries, identifying processes using the most memory and
stopping/restarting a particular service.
• PowerShell can also obtain model information on a computer and extract information on OSes,
such as the specific version and service pack levels.
• In addition, admins can use PowerShell to run commands and scripts on one or more remote
computers, using protocols such as WS-Management and, more recently, Secure Shell (SSH).
4. • PowerShell is used in IT departments to automate formerly manual tasks, with the objective of
boosting efficiency.
• Third-party IT services firms, such as managed service providers (MSPs), also use PowerShell.
• MSPs tap PowerShell to automate such tasks as software deployment, software integration
and report generation.
• Service providers also create PowerShell scripts to periodically check on whether customers
have required software installed and to automate the process of creating a new user account.
5. Powershell commands - Cmdlets
• Cmdlets are the foundational component of PowerShell automation. A cmdlet performs a
single function and returns a .NET object.
• Cmdlets are typically structured in a verb-noun format.
• One or more parameters can be added to a cmdlet to make the command more specific --
directing a cmdlet to install a particular version of a software product, for example.
• Ready-made cmdlets abound, and admins can learn about them through help content, which
describes the cmdlet and its parameters.
• Admins can create their own cmdlets using PowerShell script or C#.
• All told, thousands of cmdlets exist across PowerShell and public and private repositories.
7. Cmdlets vs. commands
• Cmdlets attempt to make it clear to the user what action they perform. That's in contrast to
the sometimes truncated and cryptic command statements used in other shells.
• Joey Aiello, senior program manager, PowerShell, at Microsoft, said PowerShell's "very verbose
syntax" simplifies matters for people who aren't as familiar with the shorter command names
used in shells such as CMD and BASH.
• On the other hand, PowerShell supports aliases for admins that are accustomed to using
shorter commands.
8. PowerShell Cmdlets
• We will discuss PowerShell cmdlets for network troubleshooting.
• The first group of cmdlets deals with displaying network information so admins can confirm
it is correct.
• The second group covers name resolution, and
• the final set looks at managing network services with PowerShell.
9. • The basic PowerShell syntax is verb-noun followed by possible parameters.
• For example,
• Get-Date displays the system's current date and time.
10. • Here are a few PowerShell tricks to remember:
• PowerShell cmdlets are not case-sensitive.
• Use the Format-Table cmdlet to organize output.
• Use the Up arrow key to browse recent commands.
• Use the Tab key after verbs to see what nouns are available -- many options are available.
• Use the Tab key after a parameter dash (-) to see the available parameters.
• Use the Tab key after a parameter to see the valid parameter values.
11. Get-NetIPAddress
• view IP address settings
• Frequently, the first step in troubleshooting a network problem is confirming the host's IP
address configuration.
• While many admins use ipconfig to display this information, the Get-NetIPAddress cmdlet
serves the same purpose.
12. Get-NetIPConfiguration
• display IP address details
• Another option is to use the Get-NetIPConfiguration cmdlet to display details about the IP
address settings. One major feature of this cmdlet is its ability to provide more focused
information. Depending on the parameters admins include, the output displays information
for specific interfaces and at varying levels of detail.
13. Get-NetAdapter
• display network interface settings
• It can be helpful to display specific information about the network card itself rather than the
logical addressing associated with it. Use the Get-NetAdapter cmdlet to see the interface's
attributes, including name, description, interface index, status, media access control address
and link speed.
14. Enable-NetAdapter and Disable-NetAdapter
• up and down an interface
• Admins may discover another admin has downed a network interface, or perhaps someone
configured the interface as a failover and kept it in the down state. They can use the Enable-
NetAdapter cmdlet to reenable -- or up -- an interface. Downing the interface relies on the
Disable-NetAdapter cmdlet.
15. Get-NetRoute
• show the routing table
• If admins are confident the system's IP address settings are correct and the network interface
is responsive, they may need to confirm the routing table.
• Rather than using the older route command, try the Get-NetRoute cmdlet instead.
16. Test-Connection and Test-NetConnection
• test connectivity
• Ping is probably the most ubiquitous network troubleshooting tool.
• PowerShell has its own cmdlet for ping: Test-Connection.
• The syntax and responses are similar to the more generic tool.
17. Get-NetTCPConnection
• test existing connections to server
• Another connectivity check is viewing existing connections to the server.
• Do this with the Get-NetTCPConnection cmdlet, which replaces the netstat command.
• The output from this command may be long depending on the current connections to the
system and the network services running on it.
• One way to narrow the scope of the results is to request current connections by a specific port
number.
• For example, perhaps admins are interested in results on port 135/TCP. In that case, they can
use the -LocalPort parameter, as seen below.
• PS>Get-NetTCPConnection –LocalPort 135
18. Resolve-DnsName
• confirm name resolution works
• Begin by attempting to resolve an IP address manually with the Resolve-DnsName cmdlet. This
cmdlet may replace or supplement nslookup in an admin's toolbox.
• PS> Resolve-DnsName google.com
19. Get-DnsClient
• check DNS client status
• Next, check the status of the DNS client software on the local machine. The Get-DnsClient
cmdlet provides this information, as seen below.
20. Get-DnsClientCache and Clear-DnsClientCache
• view and clear DNS cache
• When troubleshooting client-side name resolution problems, it's often useful to clear the DNS
cache. While the cache normally makes the name resolution process more efficient, it can
potentially store incorrect or outdated information, causing name resolution to fail or return
false results. Admins often use ipconfig /flushdns to do this, along with ipconfig /displaydns to
view the cache.
21. Get-DnsClientServerAddress
• display configured DNS servers
• Client computers may attempt to resolve names against invalid DNS servers. Display the
configured DNS servers for a client by using the Get-DnsClientServerAddress cmdlet, as seen
below.
22. Get-Service
• check service status
• Identify services either by service name or display name. A parameter exists for both options.
For example, check the status of a service by using the Get-Service -Name DhcpServer or Get-
Service -DisplayName "DHCP Server" cmdlet, as shown below.
• PS> Get-Service –Name DhcpServer
Name DisplayName
dhcp DHCP Client
DNS DNS Server
DnsCache DNS Client
TermService Remote Desktop Services
ssh-agent OpenSSH Authentication Agent
23. Restart-Service
• restart a service
• Restarting a service uses a similar cmdlet and syntax. For example, to restart the DHCP server
service, use the Restart-Service cmdlet with the -Name parameter.