Module 15 Lesson 6 of 6 🕑 ~65 min

> cat module-15-6-cybersecurity-labs-capstone.md

Cybersecurity PowerShell, Labs & Capstone

The final lesson: PowerShell as a defender's tool, hands-on labs across everything from Lessons 1–5, and a capstone project where you build your own reusable enterprise toolkit.

1 PowerShell for Cybersecurity

PowerShell matters for defenders as much as administrators — Event Log analysis, account investigations, process analysis, network connection analysis, file hashing, service inspection, certificate inspection, Active Directory investigations, incident-response collection, endpoint triage, API integration, SIEM automation, and IOC searches (Module 11 and Module 12 both draw on exactly this toolset).

Calculate a file hash with Get-FileHash ".\suspicious.exe" — typical algorithms are SHA256, SHA1, and MD5, with SHA256 commonly preferred for modern file identification (Module 12, Lesson 1's IOC discussion covers file hashes as evidence in more depth).

Check network connections with Get-NetTCPConnection (behaviour depends on Windows version), which can show local/remote address and port, connection state, and owning process ID. Correlate a suspicious remote connection back to the actual application:

Get-Process -Id 1234

Remote connection → process ID → application: the exact chain a SOC analyst walks when investigating unexpected outbound traffic (Module 11, Lesson 2).

2 Windows Event Log Investigation

PowerShell can query Windows Event Logs directly. The modern command is Get-WinEvent:

Get-WinEvent -LogName Security -MaxEvents 20

Get-WinEvent -FilterHashtable @{
    LogName = "Security"
    Id      = 4625
}

Event ID 4625 typically represents a failed logon (Module 14, Lesson 3) — this is exactly how you'd investigate repeated authentication failures from the command line instead of clicking through Event Viewer by hand. Older scripts may use Get-EventLog instead; recognise it when maintaining legacy environments, but modern scripts generally favour Get-WinEvent because it supports newer Windows event-log infrastructure and considerably more flexible filtering.

3 Common Beginner Mistakes

Running commands without understanding them
Never copy a destructive command straight from the internet into production.
Hardcoding passwords
$password = "Password123" (Lesson 5, Section 4).
Not filtering early
Get-ADUser -Filter * followed by processing hundreds of thousands of unnecessary objects, when a narrower directory query would have worked.
No error handling
Assuming every system will respond successfully — real systems fail (Lesson 5, Section 1).
No logging
Later, you can't explain what actually happened (Lesson 5, Section 2).
No testing
The script is tested for the first time against production.
Running as Domain Admin
Automation should use the minimum permissions necessary, not the broadest available.
Ignoring API rate limits
Cloud APIs may return 429 Too Many Requests (Module 13, Lesson 2) — scripts may need retry logic, backoff, pagination, and throttling awareness.
Assuming PowerShell 5.1 and 7 are identical
Module and framework compatibility can differ substantially even when the language itself looks familiar (Lesson 5, Section 6).

4 Interview Questions

What is PowerShell?
An object-oriented command-line shell and scripting language commonly used for administration and automation.
What is a variable?
Stores information that can be reused within a script.
What does the pipeline do?
Passes objects from one command to another.
What is $_?
The current object being processed in a pipeline operation.
What is a foreach loop?
Repeats an operation for every item in a collection.
Why use functions?
They allow reusable, maintainable blocks of automation instead of duplicated code.
What does Import-Csv do?
Converts CSV rows into PowerShell objects whose columns become accessible properties.
What is Invoke-RestMethod?
Lets PowerShell talk to REST APIs over HTTP/HTTPS, automatically deserialising JSON responses into objects.
Why shouldn't passwords live in scripts?
Scripts get copied, logged, emailed, committed to source control, or read by other administrators — any of which exposes the credential.
PowerShell 5.1 vs PowerShell 7?
5.1 is the Windows-only legacy version on the older .NET Framework. PowerShell 7 uses modern .NET, is cross-platform, receives active development, and can run side-by-side with 5.1.
Why is PowerShell useful for IAM?
It can automate provisioning, deprovisioning, group membership, access reviews, account reporting, Entra administration, Microsoft Graph calls, and AD administration.
Why is PowerShell useful for cybersecurity?
Log collection, endpoint investigation, file hashing, process/network investigation, AD queries, incident response, API automation, and security reporting.

Hands-On Labs

🦡 Build these yourself

🔮 Lab – Service Health Checker

Write a script that checks Spooler, WinRM, and W32Time, printing each service's status, then modify it so any stopped service prints a WARNING.

Reveal a working approach
$Services = @("Spooler", "WinRM", "W32Time")

foreach ($ServiceName in $Services) {
    $Service = Get-Service -Name $ServiceName
    if ($Service.Status -ne "Running") {
        Write-Host "WARNING: $ServiceName - $($Service.Status)"
    }
    else {
        Write-Host "$ServiceName - $($Service.Status)"
    }
}

🔮 Lab – CSV User Processing

Given a CSV of usernames/departments/locations, import it, filter to just Finance users, and export the result to a new CSV.

Reveal a working approach
$Users = Import-Csv ".\users.csv"

$FinanceUsers = $Users | Where-Object Department -eq "Finance"

$FinanceUsers | Export-Csv ".\FinanceUsers.csv" -NoTypeInformation

🔮 Lab – Event Log Investigation

Security reports multiple failed authentication attempts against a server. Retrieve Event ID 4625 from the Windows Security log and identify what you'd investigate next.

Reveal the approach
Get-WinEvent -FilterHashtable @{
    LogName = "Security"
    Id      = 4625
}

Then examine timestamp, username, source workstation, authentication type, and frequency — exactly the same investigative questions Module 14, Lesson 3 taught for a raw 4625 event, now automated instead of clicked through manually.

🔮 Lab – Bearer Token Authentication

Using a training token, build a header hash table and call an authenticated endpoint. Then deliberately test with no token, an invalid token, and an expired token. What HTTP responses do you expect for each?

Reveal the expected pattern

No token or an invalid/expired one should all return 401 Unauthorized (Module 13, Lesson 2); only a genuinely valid token should succeed. This ties together authentication, APIs, OAuth, JWT, and PowerShell all at once — exactly Lesson 3's point about this module connecting concepts from across the whole course.

🔮 Lab – Onboarding Simulator

Given a CSV of new hires, write a script that generates a display name, email address, and group for each row, and writes the intended action to a log — without creating any real AD users.

Reveal expected output
CREATE USER: asmith
EMAIL: alice.smith@example.com
DEPARTMENT: Finance
GROUP: GRP-Finance-Users
STATUS: READY

This is the safe simulate-before-execute pattern from Lesson 4's bulk IAM automation, applied to onboarding instead of offboarding.

Capstone – Enterprise Support Toolkit

🦡 Final project

Scenario: users report that an internal authentication application is unavailable. Build AuthenticationHealthCheck.ps1, checking DNS resolution, ping/connectivity, TCP 443, the Windows service, disk space, CPU, memory, recent application errors, an API health endpoint, and certificate expiry — producing output like:

===== AUTHENTICATION SYSTEM HEALTH =====

DNS                    PASS
HTTPS 443              PASS
Authentication Service PASS
Disk Space             WARNING
API Health             FAIL
Certificate            PASS
Event Log Errors       14

Overall Status: DEGRADED

Export a matching AuthenticationHealthCheck.csv for escalation (Module 14, Lesson 6's escalation-with-evidence discipline applies directly here). This is very close to real automation engineers build in real organisations.

Broaden it into a full toolkitEnterpriseSupportToolkit.ps1 containing at least five reusable functions (e.g. Test-Server, Test-Port, Get-DiskHealth, Get-ServiceHealth, Test-API, Get-RecentErrors, Get-SystemInformation), demonstrating variables, arrays, hash tables, conditions, loops, functions, pipeline processing, CSV import/export, JSON, REST APIs, error handling, and logging. Bonus: support multiple servers, produce CSV and JSON reports, use -Verbose, validate parameters, handle offline systems and HTTP failures gracefully, and contain zero hardcoded credentials.

Be ready to explain: what the script does, why you automated it, how errors are handled, how secrets are protected, how you tested it, how you'd deploy it safely, and how you'd roll back changes. A student who can build and explain this project has moved past memorising PowerShell syntax and started thinking like an IT engineer.

Module 15 Outcome

The most important lesson in this module was never "how do I write a loop?" It's how do I recognise a manual process that should become safe, repeatable automation? If an engineer spends 20 minutes every morning checking a server, a service, disk space, an API, a certificate, and logs, that's 20 minutes × 250 working days — and also a clear candidate for a HealthCheck.ps1 that produces the same report every time, consistently, without anyone having to remember all six steps.

But automation amplifies mistakes exactly as readily as it amplifies good work. A command executed manually might damage one object; an incorrectly written loop can damage ten thousand. Professional automation is therefore never just "PowerShell knowledge" — it's PowerShell knowledge combined with testing, least privilege, error handling, logging, change management, code review, and security, all at once. That combination is the actual difference between knowing PowerShell commands and being able to use PowerShell professionally.

Across all 6 lessons, you should now be able to explain that PowerShell is an enterprise automation platform, not just a command prompt; that objects and the pipeline are fundamental to how it works; that loops let operations scale from one system to thousands; that CSV and JSON are the two data formats enterprise automation runs on; that Invoke-RestMethod connects PowerShell directly to the API and authentication knowledge from Modules 9 and 13; that Windows PowerShell 5.1 and modern PowerShell 7 coexist in real enterprises for good reasons; that legacy technologies like WMI and AzureAD/MSOnline are still genuinely common; that PowerShell is a real cybersecurity and incident-response tool, not just an admin one; and that credentials, execution policy, testing, and least privilege all matter more than clever syntax. That's the real PowerShell skill: recognising repetitive IT work and turning it into safe, auditable, repeatable automation.