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

Reading Logs and Hardening Basics

Windows logs record sign ins, service changes, and scheduled tasks. This lesson shows how to read those logs, spot signs worth investigating, and follow up with simple hardening steps.

Lesson 4 of 4 in Chapter 16: PowerShell for Ethical Hackers. Previous step in this path: Reading Network Listeners, Domain Objects, and Shares. 3 learning objectives, 5 examples, and a knowledge check.

Start: what you will learn

Windows logs record sign ins, service changes, and scheduled tasks. This lesson shows how to read those logs, spot signs worth investigating, and follow up with simple hardening steps.

Learning objectives

  • Read Windows logs with Get-WinEvent and filter by log name and event id
  • Spot failed logons, new services, and new scheduled tasks as signs to investigate
  • Explain hardening follow ups, including disabling what is not needed, removing stale accounts, and keeping systems updated

Concept in simple words

What it is: Log reading means checking the records Windows keeps about what happened on a computer. This is for your OWN lab only, with permission, for understanding and defense. An event log is a dated record book, and an event id is the number that tells you what kind of event it was, such as a failed logon.

Why it works

Why it exists: Attacks and mistakes both leave traces, but a trace only helps if someone reads it. Failed logons can mean a wrong password, or repeated guessing. A new service can mean new software, or a change no one planned. A new scheduled task, which is a job Windows runs at a set time, can mean a planned update, or a job no one approved. Logs turn a guess into a dated fact to check.

What problem it solves: Without logs, a defender must rely on memory and on what is visible now. A service installed last week, a logon that failed ten times at night, or a task created yesterday would all be invisible today. Logs solve that memory problem by keeping a dated, ordered record that you can filter by log name, event id, and time. That record lets you answer when, not just what.

What PowerShell is doing behind the command: Get-WinEvent asks the Windows event log service for event objects. Each event object has TimeCreated, Id, LevelDisplayName, ProviderName, and Message, plus a Properties array with the detailed fields for that event type. The -FilterHashtable parameter passes your filter to the log service, so only matching events are returned, instead of PowerShell reading the whole log and throwing most of it away. That is why a filter with LogName and Id is both faster and easier to read than reading everything and filtering afterwards.

Logs in depth, Security and System: The Security log holds audit events, such as logons, account changes, and task creation, when auditing is turned on. The System log holds events from Windows parts and services, such as service installation. Picking the right log matters, because the same idea can live in different logs. A failed logon lives in Security. A new service installed event lives in System for id 7045, and a related service installed audit event lives in Security for id 4697. If you look in the wrong log, you will find nothing, and nothing is not the same as no event happened.

Event ids in depth: Event id 4625 means an account failed to log on. Event id 4624 means an account successfully logged on, and comparing 4625 with 4624 helps you see whether failures were followed by a success. Event id 7045 in the System log means a service was installed on the system. Event id 4698 in the Security log means a scheduled task was created. Event id 4697 in the Security log means a service was installed. Learn these five as a set, because together they cover logons, services, and tasks, which are the three changes a defender watches first.

Reading one event well: A good event reading answers five questions. When did it happen, from TimeCreated. What kind of event was it, from Id. Which account was involved, from the Message or the Properties. Which computer recorded it. And what does the Message actually say, in full, not just the first line. The Message is a summary written for a human reader, but the Properties hold the exact fields. For a first review, TimeCreated, Id, and Message are enough. For a deeper check, a defender reads the full event, including the account and source details.

Patterns beat single events: One failed logon is usually a typo. Ten failed logons for one account in ten minutes is a pattern. One new service after you installed software is expected. A new service at a time when no one installed anything is a question. One new scheduled task for a planned update is normal. A new task with a name you cannot explain, created outside lab hours, is a stronger question. Always count, check the time window, and compare with what you did yourself in the lab before you judge.

Time windows in depth: A filter without a time limit can return old events that have nothing to do with today. Adding StartTime to a filter, for example StartTime set to one day ago, limits the search to recent events. That makes the result smaller, faster, and easier to connect to lab work you remember. For a baseline, a longer window is fine. For a question like what changed today, a short window is better. Always write the window in your notes, so a defender knows whether you looked at one day or one month.

Think of it like this

Think of it like this: Think of logs like a building entry book. The book does not stop anyone, but it shows who tried each door, when, and whether the door opened. If one door shows many failed tries at night, you do not ignore the book. You ask who tried it, and why. A single failed try is like a visitor trying the wrong key once. Many failed tries in a row are like someone testing keys on purpose, and that pattern is what the book is for.

How it works, step by step

How it works, step by step: First, pick a log, such as Security for logons or System for services, and keep the number of events small so you can read them. Second, filter by event id, for example 4625 for a failed logon in the Security log, 7045 for a new service in the System log, and 4698 for a new scheduled task in the Security log. Third, read the time, the account name, and the computer name in each event. Fourth, compare what you see with what you expected, and write down anything that does not match.

A careful order for one log review: Start with the narrowest question you have, such as failed logons in the last day. Read those events fully. Then widen only if the pattern needs it, for example by checking successful logons for the same account, or by checking the same time window for new services and new tasks. Widening in that order keeps you from drowning in unrelated events, and it builds a small story: what was tried, what succeeded, and what changed.

Let us walk through an example: Suppose you filter the Security log in your lab and you see several failed logons for one account in a short time. You write down the times, the account name, and the source computer if the event shows one. Then you check whether you caused those failures yourself while testing in the lab. If you did not, you flag the pattern for a defender, and you do not try the password yourself to see if it works. Trying it would turn a log review into a password test, and that is out of scope.

A second walkthrough, a new service: Suppose you filter the System log for id 7045 and you see a service installed at a time when you were not installing software. You write down the time, the service name from the Message, and the account shown in the event if there is one. Then you check your lab notes for that day. If no lab task explains it, you flag it. The defender can then check install records and decide whether the service belongs. Your log note is what makes that check possible.

A third walkthrough, a new scheduled task: Suppose you filter the Security log for id 4698 and you see a task created with a name you do not recognise. You write down the time, the task name, and the account that created it, as shown in the event. You do not run the task, open its action, or change it on a system you do not manage. You flag it, because a task is a future action, and an unapproved future action deserves review before it runs again.

Hardening follow up in depth: Hardening means making a system smaller, simpler, and harder to misuse, after a finding. Disabling what is not needed means a service or feature that serves no lab purpose should not stay running, because every running part is a chance for misuse. Removing stale accounts means accounts no one uses should not stay enabled, because every enabled account is a door. Keeping systems updated means applying fixes for known faults, so a known weakness does not stay open. Least privilege means each account gets only the access it truly needs for its job, and no more. These are defender actions on a system the defender manages, not actions for a learner to take on a system they do not own.

How findings connect to hardening: A failed logon pattern points to password and lockout review by the defender, and to checking whether the account is still needed. A new service points to a review of what software is installed and whether that service is needed. A new scheduled task points to a review of which tasks are approved and which are not. A stale account points directly to removal or disabling by the defender. The log does not fix the system. The log tells the defender where to look, and hardening is the fix that follows.

When to use it

When to use it, and when not to: Use log reading on your own lab, or on a lab system you have clear permission to review. Do not read logs on a system you do not own, and do not use a log entry as an excuse to test a password, reuse a credential, or change a task you do not manage. The follow up belongs to the defender who owns the system. Your role in this chapter is to read, record, and flag, clearly and calmly.

Scope and safety, stated plainly: This lesson is for your own lab only, with permission, for defense and understanding. It does not teach how to hide, change, or delete log entries, how to bypass auditing, how to guess or test passwords, or how to use a log entry to gain access. Logs are evidence for a defender. Treating them as a tool for hiding or for access would break the whole purpose of this chapter, so never go in that direction.

Edge cases to know: A Security log can be empty for an event type if auditing for that type is not turned on, and empty does not mean nothing happened. It means nothing was recorded, and a defender must check the audit setting itself. A Message can be truncated in a table view, so a short Message is not the full event. A time in a log is the time on that computer, so compare it with lab notes from the same computer, not with a clock from another time zone without noting the difference. An event id can appear in more than one log with a different meaning, so always record LogName together with Id.

How to keep log notes that a defender can use: For each pattern, write the log name, the event id, the time window, the command you ran, the count of events, the account names involved, and your question. A note that says five failed logons for LabUser between 10:00 and 10:10, Security log, id 4625, not caused by my lab testing, is a note a defender can act on at once. A note that says lots of failures is not.

Worked examples

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

Syntax

Syntax
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625 }

Example 1

Walkthrough: Get-WinEvent reads Windows event logs. The -FilterHashtable value is a table of keys and values in braces. LogName Security picks the Security log, and Id 4625 picks only failed logon events. The -MaxEvents 10 parameter keeps the result to ten events, so you can read them all. Select-Object shows TimeCreated, Id, and Message, so you can read when each failure happened. What to look for: the times, whether failures cluster close together, and whether one account repeats. What changes if you change one part: if you change 4625 to 4624, you see successful logons instead, which helps you check whether failures were followed by a success. If you remove -MaxEvents, you may get a very long list, which is harder to read and slower to return.

Example 1
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625 } -MaxEvents 10 | Select-Object TimeCreated, Id, Message

Illustrative output: TimeCreated Id Message ----------- -- ------- 11/3/2026 10:00:00 AM 4625 An account failed to log on.

Example 2

Walkthrough: This reads the System log instead of the Security log. Event id 7045 means a new service was installed on the system. Keeping the result to ten events makes it easy to compare each new service with software you actually installed in the lab. What to look for: the time of each install, and whether it matches a lab install you remember. What changes if you change one part: if you change System to Security and 7045 to 4697, you ask the Security log for its own service installed audit event, which is a related but separate record. If you change 7045 to another System id, you ask a different question entirely, so always pair LogName and Id together in your notes.

Example 2
Get-WinEvent -FilterHashtable @{ LogName = 'System'; Id = 7045 } -MaxEvents 10 | Select-Object TimeCreated, Id, Message

Illustrative output: TimeCreated Id Message ----------- -- ------- 11/3/2026 10:05:00 AM 7045 A service was installed on the system.

Example 3

Walkthrough: Get-WinEvent reads the Security log. The filter picks only event id 4698, which means a scheduled task was created. The -MaxEvents 10 limit keeps the list readable. Select-Object shows TimeCreated, Id, and Message, where the Message names the task. What to look for: task names you recognise from planned lab work, and any task name you cannot explain. What changes if you change one part: if you change 4698 to 4699, you see tasks that were deleted, which is a different history. If you remove the Id from the filter, you get every Security event, which is far too broad for a task review.

Example 3
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4698 } -MaxEvents 10 | Select-Object TimeCreated, Id, Message

Illustrative output: TimeCreated Id Message ----------- -- ------- 11/3/2026 10:10:00 AM 4698 A scheduled task was created.

Example 4

Walkthrough: This filter has three keys. LogName Security picks the log, Id 4625 picks failed logons, and StartTime limits the search to recent events. The value (Get-Date).AddDays(-1) means the current date and time, minus one day, so only events from the last day are returned. The parentheses make PowerShell run Get-Date first, then AddDays on that result. Select-Object shows TimeCreated, Id, and Message. What to look for: recent failures only, which you can compare with lab work you did today or yesterday. What changes if you change one part: if you change AddDays(-1) to AddHours(-2), you narrow the window to the last two hours. If you remove StartTime, you widen the search to older events, which may hide today pattern in old noise.

Example 4
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625; StartTime = (Get-Date).AddDays(-1) } -MaxEvents 10 | Select-Object TimeCreated, Id, Message

Illustrative output: TimeCreated Id Message ----------- -- ------- 11/3/2026 10:00:00 AM 4625 An account failed to log on.

Example 5

Walkthrough: Get-WinEvent with -ListLog and a star lists the event logs on the computer, instead of reading events inside one log. Each result is a log object with LogName and RecordCount, which is how many records that log holds. Where-Object keeps only logs where RecordCount is greater than 0, so empty logs are left out. Select-Object shows LogName and RecordCount, and -First 10 keeps the list short. What to look for: which logs actually hold records on your lab machine, so you know where to search next. What changes if you change one part: if you remove the Where-Object filter, you also see empty logs, which is useful for a full inventory but noisy for a quick check. If you change -First 10 to a larger number, you see more logs, but the list becomes harder to skim.

Example 5
Get-WinEvent -ListLog * | Where-Object { $_.RecordCount -gt 0 } | Select-Object LogName, RecordCount -First 10

Illustrative output: LogName RecordCount ------- ----------- Security 1240 System 3120

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.

  • Reading logs on a system you do not own, or using a failed logon entry as a reason to test passwords or reuse credentials.
  • Reading only one event and jumping to a conclusion, instead of looking for a pattern across time, such as many failures in a short period.
  • Finding a problem and stopping there, without noting the hardening follow up, such as disabling what is not needed, removing a stale account, or updating the system.
  • Looking in the wrong log for an event id, then concluding nothing happened, when the event was recorded in a different log, or was not audited at all.
  • Recording an event id without its log name, so a defender cannot repeat your search, because the same idea can live in more than one log.
  • Reading only the short Message in a table and missing the full event details, such as the account or source, that change what the event means.
  • Using a filter with no time window and no limit, then skimming a huge result and missing the recent pattern that mattered.

Knowledge check

Knowledge check

You see many failed logons for one account in a short time in your lab logs. What is the best defender first step?

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

Remember this and next step

Remember this: Logs do not prove an attack by themselves, but failed logons, new services, and new scheduled tasks are strong reasons to investigate. Hardening follows the finding: disable what is not needed, remove stale accounts, keep systems updated, and give each account only the access it truly needs, which is called least privilege. Read in your own lab, record the pattern, flag it, and leave the fix to the defender who owns the system.

Next step: Execution policy and script signing