Security Power Level: Advanced Chapter 16: PowerShell for Ethical Hackers

The Safe Enumeration Mindset

Enumeration means listing what exists on a system so you can understand it. You do it only in your own lab, with permission, and you write down what you find so a defender can act on it.

Lesson 1 of 4 in Chapter 16: PowerShell for Ethical Hackers. Previous step in this path: CSV: import and export. 3 learning objectives, 5 examples, and a knowledge check.

Start: what you will learn

Enumeration means listing what exists on a system so you can understand it. You do it only in your own lab, with permission, and you write down what you find so a defender can act on it.

Learning objectives

  • Define enumeration in plain words and explain why scope and permission come first
  • Describe how to document findings clearly, without changing the system
  • Explain how a defender uses the same view to find problems early

Concept in simple words

What it is: Enumeration means making a careful list of what exists on a computer, such as running programs, services, accounts, and network listeners. This lesson, and this whole chapter, is for your OWN lab only, with permission, for understanding and defense. You never run these checks on a system you do not own or do not have clear permission to check. That limit is not a small detail. It is the rule that makes the whole chapter safe to learn from.

Why it works

Why it exists: A defender cannot protect what they cannot see. A clear list shows what should be there and what should not be there. When you compare a list from today with a list from last week, a new item stands out fast. That early warning is the whole point. Without a list, a defender must guess. With a list, a defender can check facts, dates, and names.

What problem it solves: Computers change quietly. Software installs a background service. A test account stays behind after a lab exercise. A program starts to listen on a new port. None of these changes announce themselves on the desktop. Enumeration solves that quiet change problem by turning the hidden state of a machine into a readable list you can review line by line.

What PowerShell is doing behind the command: When you run a Get command, PowerShell asks Windows for objects, not for plain text. An object is a bundle of facts about one thing, such as one process, with properties like Name and Id. PowerShell then shows you the properties you asked for in a table. That is why you can filter, sort, and select columns. You are not reading a screen of typed text. You are reading structured facts that Windows already holds.

Why read only matters: A read only command asks a question. It does not change a setting, stop a service, delete an account, or open a file. That matters for two reasons. First, you cannot break your lab by looking. Second, you do not destroy the evidence a defender needs. If you change something first and ask questions later, the original state is gone, and no one can prove what was there before you acted.

Think of it like this

Think of it like this: Think of enumeration like taking stock in a small shop. You walk the shelves, you write down every item, and you note anything you do not recognise. You do not move stock, you do not break locks, and you do not take anything. You just make the list honest and complete. A shop owner trusts that kind of list because nothing was touched while it was made.

How it works, step by step

How it works, step by step: First, confirm your scope, which means the exact computer or lab you are allowed to check, and stop if anything is unclear. Second, use read only commands, which are commands that show information without changing settings. Third, save your notes with the date, the computer name, the command you ran, and what you saw. Fourth, flag anything odd for a defender to review, and do not try to fix a live system you do not manage.

Step 1 in detail, confirm scope: Scope answers three questions. Which computer is it. Whose permission covers it. What are you allowed to read. If you cannot answer all three, you do not start. A vague feeling of permission is not permission. Clear permission means you own the lab machine, or the person who manages it has said yes to this exact check.

Step 2 in detail, read only first: Start with Get commands. Get means retrieve. It does not mean set, stop, remove, or change. If a command name starts with Set, Stop, Remove, or New, pause and ask whether that change belongs to you and whether it is needed. In this chapter, the learning commands are Get commands, so you can practise safely.

Step 3 in detail, write notes you can trust: A good note has the date and time, the computer name, the exact command, the full output or the part that matters, and your question about it. Write the question in plain words, for example, I did not expect this service, where did it come from. A note without a date cannot be compared with next week. A note without the command cannot be repeated or checked.

Step 4 in detail, flag, do not fix on your own: Flagging means passing the note to the defender who manages the system, with the facts and no guess about guilt. A new service is not proof of an attack. It may be normal software. It may be a leftover from a lab task. The defender can check install dates, software lists, and change records. Your job is to make that check easy, not to act first.

How a defender uses the same view: A defender builds a baseline, which is a trusted list made when the system is known to be clean and normal. Later lists are compared with the baseline. A new process, a new service, a new account, or a new listener is then easy to spot, because it was not in the baseline. This is why the same commands help both a learner and a defender. The learner learns what normal looks like. The defender watches for drift away from normal.

Let us walk through an example: Suppose you list the services on your own lab computer and you see a service name you do not recognise. You do not stop it right away, and you do not delete it. You write down its name, its status, and the time you saw it. Then you check whether it came with software you installed, and you ask a defender to confirm what it is. That careful pause is good practice. It protects the lab, and it protects you from acting on a guess.

A second walkthrough, comparing two days: On Monday you save a short list of running services in your lab. On Friday you run the same command again. One new service appears. Because you have the Monday list, you can name the change exactly, and you can ask when it appeared. Without the Monday list, the Friday list would look normal, and the change would hide in plain sight. That is the power of a baseline.

What a good finding looks like: A good finding is short, factual, and checkable. It says what you ran, when you ran it, what you saw, what you expected, and what question remains. It does not say this is an attack. It does not say this is safe. It says here is a difference, please check it. That tone helps a defender act fast, because no time is wasted untangling drama from facts.

When to use it

When to use it, and when not to: Use enumeration when you are learning, auditing your own lab, or helping a defender review a system you are allowed to review. Do not use it on a network you do not own, another person computer, a shared system you do not manage, or any public system, even if you are only looking. Looking without permission is still out of scope, so stay inside your own lab.

Scope and safety, stated plainly: This lesson teaches defense and understanding only, in your own lab, with permission. It does not teach how to gain access you do not have, how to raise your privileges, how to take or guess passwords, how to move from one machine to another, how to bypass a control, or how to hide or change logs. If a thought leads in any of those directions, stop, and bring the question back to what a defender should record and report.

Common traps in your own thinking: The first trap is curiosity without a boundary, where looking feels harmless because nothing is changed. The second trap is speed, where you run many commands and save nothing, so nothing can be checked later. The third trap is certainty, where an unknown name feels like proof of something bad. Slow down, save the note, and let the facts lead. That is the habit that separates a careful defender from a careless explorer.

How to practise this lesson well: Pick one lab computer. Run one Get command. Save the output with the date. Read every line, even the boring ones. Circle one name you cannot explain yet, and write one question about it. Then stop. That small, complete loop is better than ten rushed commands with no notes. Repeat it next week and compare.

Worked examples

Read each example in order. Each one explains its parts, then shows what to look for in the output.

Example 1

Walkthrough: Get-Process asks Windows for the running programs, called processes, as objects. The pipe, written as |, passes those objects to the next step. Select-Object keeps only the Name and Id properties, so the table stays readable. Name is the program name, and Id is the unique number for that one running instance. The -First 5 part keeps only the first five rows. What to look for: short, familiar names at first, and any name you cannot explain, which you note rather than act on. What changes if you change one part: if you remove -First 5, you get the full list, which is more complete but harder to read. If you remove Select-Object, you get many more columns, which can hide the simple facts you need.

Example 1
Get-Process | Select-Object Name, Id -First 5

Illustrative output: Name Id ---- -- pwsh 1234 notepad 2345

Example 2

Walkthrough: Get-Service lists services, which are background programs that Windows runs for you. Where-Object keeps only rows where the Status property equals Running, because a running service is the one doing work right now. The $_ symbol means the current row being tested. Select-Object then shows only Name and Status, and -First 5 keeps the list short. What to look for: services you expect from normal Windows work, and any running service you did not expect. What changes if you change one part: if you change Running to Stopped, you see services that are present but not running, which is a different question. If you remove Where-Object, you see every service, running or not, which is useful for a full baseline but noisy for a quick check.

Example 2
Get-Service | Where-Object { $_.Status -eq 'Running' } | Select-Object Name, Status -First 5

Illustrative output: Name Status ---- ------ Spooler Running WinRM Running

Example 3

Walkthrough: Get-Process lists processes. Sort-Object CPU -Descending reorders the objects so the highest CPU value comes first. CPU here is total processor time used by the process, not a live percent, so a long running program can rank high even when it is quiet now. Select-Object shows Name, Id, and CPU, and -First 5 keeps only the top five. What to look for: a familiar heavy program at the top, or an unknown program using far more processor time than the rest. What changes if you change one part: if you remove -Descending, the smallest CPU values come first, which answers a different question. If you sort by WorkingSet instead of CPU, you rank by memory in use, which is useful when a machine feels slow for memory reasons.

Example 3
Get-Process | Sort-Object CPU -Descending | Select-Object Name, Id, CPU -First 5

Illustrative output: Name Id CPU ---- -- --- pwsh 1234 12.5 notepad 2345 0.4

Example 4

Walkthrough: Get-Service with -Name Spooler asks for one named service only, instead of the whole list. Spooler is the Print Spooler service, a normal Windows service, used here only as a safe, familiar example. Select-Object shows Name, which is the short service name, DisplayName, which is the friendly name, Status, which tells you if it is running, and StartType, which tells you how Windows starts it, such as Automatic or Manual. What to look for: a Status and StartType pair that matches what you expect for that service. What changes if you change one part: if you change Spooler to another service name you know, you check that service instead. If you type a name that does not exist, you get an error, not an empty table, and that error tells you the name was wrong, not that the service is hidden.

Example 4
Get-Service -Name Spooler | Select-Object Name, DisplayName, Status, StartType

Illustrative output: Name DisplayName Status StartType ---- ----------- ------ --------- Spooler Print Spooler Running Automatic

Example 5

Walkthrough: Get-ComputerInfo asks Windows for a bundle of system and operating system facts. The -Property parameter limits the answer to only the properties you name, which keeps a very large result small and readable. WindowsProductName is the product name Windows reports, OsVersion is the operating system version, and OsArchitecture tells you whether the system is 64 bit or 32 bit. What to look for: facts that match the lab machine you expect, and a version you can write in your notes. What changes if you change one part: if you remove -Property, you get a very long list of more than a hundred properties, which is hard to read. If you add a property name that does not exist, that column comes back empty, so check the spelling and use a property you have seen before.

Example 5
Get-ComputerInfo -Property WindowsProductName, OsVersion, OsArchitecture

Illustrative output: WindowsProductName : Windows 11 Pro OsVersion : 10.0.26100 OsArchitecture : 64-bit

Nothing on this page executes PowerShell code. The outputs above are illustrative only.

Common mistakes and troubleshooting

Read these before you try the examples, so you can spot the same problems in your own work.

  • Running enumeration on a system you do not own or do not have clear permission to check, even if you only plan to look and change nothing.
  • Skipping notes, so a strange finding cannot be checked later because the date, the computer, and the command were never written down.
  • Changing or stopping something the moment it looks odd, before you understand what it is, which can break a lab system and hide the evidence a defender needs.
  • Saving only the strange line and throwing away the rest of the list, so a defender cannot tell whether the strange line was new or was always there.
  • Reading a name and deciding it is bad because it sounds odd, instead of checking whether normal software on your lab machine uses that name.
  • Running a wide check with no filter and no limit, then skimming only the top of a huge table and missing the important row further down.
  • Mixing two different days or two different computers in one note, so a later comparison compares the wrong lists and creates a false alarm.

Knowledge check

Knowledge check

What must come first before you enumerate a system?

Pick one answer. Feedback appears right away, and you can try again.

Remember this and next step

Remember this: Permission comes first, scope comes second, and notes come third. A good list, made in your own lab, helps a defender find problems early, and that is the skill this chapter builds. Read only, write it down, flag what is odd, and never turn a learning check into access you were not given.

Next step: Reading Your Own System and Services