2.3 Lab - Using Windows PowerShell
2.3 Lab - Using Windows PowerShell
2.3 Lab - Using Windows PowerShell
Objectives
The objective of the lab is to explore some of the functions of PowerShell.
Background / Scenario
PowerShell is a powerful automation tool. It is both a command console and a scripting language. In this lab,
you will use the console to execute some of the commands that are available in both the command prompt
and PowerShell. PowerShell also has functions that can create scripts to automate tasks and work together
with the Windows Operating System.
Required Resources
∙ 1 Windows PC with PowerShell installed and Internet access
a. PowerShell commands, cmdlets, are constructed in the form of verb-noun string. To identify the
PowerShell command to list the subdirectories and files in a directory, enter Get-Alias dir at the
PowerShell prompt.
© Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 1 o
f 5 www.netacad.com
Lab - Using Windows PowerShell
CommandTypeNameVersionSource
----------------------------
Aliasdir -> Get-ChildItem
NETSTAT [-a] [-b] [-e] [-f] [-n] [-o] [-p proto] [-r] [-s] [-x] [-t] [interval]
-a Displays all connections and listening ports.
-b Displays the executable involved in creating each connection or listening port.
In some cases well-known executables host multiple independent components, and in
these cases the sequence of components involved in creating the connection or
listening port is displayed. In this case the executable name is in [] at the bottom,
on top is the component it called, and so forth until TCP/IP was reached. Note that
this option can be time-consuming and will fail unless you have sufficient
permissions.
<some output omitted>
b. To display the routing table with the active routes, enter netstat -r at the prompt.
PS C:\Users\CyberOpsUser> netstat -r
===========================================================================
Interface List
3...08 00 27 a0 c3 53 ......Intel(R) PRO/1000 MT Desktop Adapter
10...08 00 27 26 c1 78 ......Intel(R) PRO/1000 MT Desktop Adapter #2
1...........................Software Loopback Interface 1
===========================================================================
© Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 2 of 5 www.netacad.com
Lab - Using Windows PowerShell
d. The netstat command can also display the processes associated with the active TCP connections. Enter
the netstat -abno at the prompt.
PS C:\Windows\system32> netstat -abno
© Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 3 o
f 5 www.netacad.com
Lab - Using Windows PowerShell
Active Connections
Proto Local Address Foreign Address State PID TCP 0.0.0.0:135 0.0.0.0:0
LISTENING 756 RpcSs
[svchost.exe]
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING 4 Can not obtain ownership
information
TCP 0.0.0.0:49664 0.0.0.0:0 LISTENING 444 Can not obtain ownership
information
TCP 0.0.0.0:49665 0.0.0.0:0 LISTENING 440 Schedule
[svchost.exe]
TCP 0.0.0.0:49666 0.0.0.0:0 LISTENING 304 EventLog
[svchost.exe]
TCP 0.0.0.0:49667 0.0.0.0:0 LISTENING 1856 [spoolsv.exe]
TCP 0.0.0.0:49668 0.0.0.0:0 LISTENING 544 <some output omitted>
e. Open the Task Manager. Navigate to the Details tab. Click the PID heading so the PID are in order.
f. Select one of the PIDs from the results of netstat -abno. PID 756 is used in this example.
g. Locate the selected PID in the Task Manager. Right-click the selected PID in the Task Manager to open
the Properties dialog box for more information.
What information can you get from the Details tab and the Properties dialog box for your selected PID?
Svchost.exe, PID 975, status Running, User name NETWORK_SERVICE, memory 9
296 K
© Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 4 of 5 www.netacad.com
Lab - Using Windows PowerShell
Step 5: Empty recycle bin using PowerShell.
PowerShell commands can simplify management of a large computer network. For example, if you wanted to
implement a new security solution on all servers in the network you could use a PowerShell command or
script to implement and verify that the services are running. You can also run PowerShell commands to
simplify actions that would take multiple steps to execute using Windows graphical desktop tools.
a. Open the Recycle Bin. Verify that there are items that can be deleted permanently from your PC. If not,
restore those files.
b. If there are no files in the Recycle Bin, create a few files, such as text file using Notepad, and place them
into the Recycle Bin.
c. In a PowerShell console, enter clear-recyclebin at the prompt.
PS C:\Users\CyberOpsUser> clear-recyclebin
Confirm
Are you sure you want to perform this action?
Performing the operation "Clear-RecycleBin" on target "All of the contents of the
Recycle Bin".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is
"Y"): y
What happened to the files in the Recycle Bin?
They all disappeared and were recycled
Reflection
PowerShell was developed for task automation and configuration management. Using the Internet, research
commands that you could use to simplify your tasks as a security analyst. Record your findings.
Dir, recycle, clear, get-eventLog, get-process, stop-process etc.
© Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 5 of 5 www.netacad.com