# PowerShell for Security

> Use PowerShell to query Windows systems, event logs and Active Directory, and understand why attackers love it too. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/cybersecurity/powershell
Last updated: 2026-11-28

Use PowerShell to query Windows systems, event logs and Active Directory, and understand why attackers love it too.

Beginner · about 12 hours · difficulty 2/5

Learn first: [Windows Internals for Defenders](https://www.internhack.in/roadmaps/tracks/cybersecurity/windows-fundamentals)

**PowerShell** is the admin language of Windows. Defenders use it to hunt across endpoints and pull event logs; attackers use it because it is already installed and powerful. Knowing it well helps on both sides.

### Core concepts

- Commands are **cmdlets** named Verb-Noun: `Get-Process`, `Get-Service`, `Get-ChildItem`.
- Pipelines pass **objects**, not text: `Get-Process | Where-Object CPU -gt 100 | Select-Object Name, Id`.
- `Get-Help` and `Get-Member` show what a command does and what properties an object has.
- Scripts are `.ps1` files; execution policy controls whether they run (it is a safety net, not a security boundary).

### Security uses

- `Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625}` to pull failed logons.
- `Get-LocalUser`, `Get-ScheduledTask`, and registry queries for persistence hunting.
- The ActiveDirectory module (`Get-ADUser`, `Get-ADGroupMember`) for auditing privileged groups.

### Defending against malicious PowerShell

Attackers use encoded commands (`-EncodedCommand`), download cradles and in-memory execution. Defenders enable **Script Block Logging** (event 4104), **Module Logging**, **Constrained Language Mode** and **AMSI**, then alert on suspicious patterns.

### Pitfalls

- Treating output as text and parsing it with regex when you could just select object properties.

Good enough to move on: you can write a script that exports the last 24 hours of failed logons to CSV grouped by account and source.

## Key concepts

- **Cmdlets and Verb-Noun naming**
- **Object pipelines**
- **Get-WinEvent for log queries**
- **ActiveDirectory module**
- **Script Block Logging and AMSI**
- **Execution policy**

## Other options for this step

- [Python for Security](https://www.internhack.in/roadmaps/tracks/cybersecurity/python-basics): Learn enough Python to parse logs, call APIs, work with files and sockets, and write your own small security tools.
- [Bash Scripting for Security](https://www.internhack.in/roadmaps/tracks/cybersecurity/bash-scripting): Automate Linux tasks with Bash scripts: loops, conditionals, pipelines and quick one-off tools for log triage and recon in labs.

## Mini project

Write a PowerShell script that lists autostart entries (Run keys, services, scheduled tasks) on a machine and exports them to CSV for baseline comparison.

## Check yourself

Why is PowerShell execution policy not considered a security control?

## Free resources

- [PowerShell documentation](https://learn.microsoft.com/en-us/powershell/) (Microsoft)
- [Get-WinEvent reference](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.diagnostics/get-winevent) (Microsoft)

Previous: [Bash Scripting for Security](https://www.internhack.in/roadmaps/tracks/cybersecurity/bash-scripting) · Next: [Automating Security Tasks and APIs](https://www.internhack.in/roadmaps/tracks/cybersecurity/security-automation)

## More in Scripting and Automation

- [Python for Security](https://www.internhack.in/roadmaps/tracks/cybersecurity/python-basics)
- [Bash Scripting for Security](https://www.internhack.in/roadmaps/tracks/cybersecurity/bash-scripting)
- [PowerShell for Security](https://www.internhack.in/roadmaps/tracks/cybersecurity/powershell)
- [Automating Security Tasks and APIs](https://www.internhack.in/roadmaps/tracks/cybersecurity/security-automation)
- [Git and GitHub for Security Work](https://www.internhack.in/roadmaps/tracks/cybersecurity/git)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Cybersecurity Roadmap](https://www.internhack.in/roadmaps/tracks/cybersecurity)
