Skip to content
Pwnversity
FUND-PSbasic · 12 min · upd. 2026-11

The Windows Console: CMD and PowerShell

As soon as you get a shell on a Windows box, everything you do goes through one of its two consoles: CMD or PowerShell. Being comfortable in them is the difference between enumerating a machine in two minutes and fighting for half an hour with Linux commands that don’t exist. And PowerShell isn’t “another Bash”: it works with objects, not text, and that changes how you filter and search.

CMD PowerShell
Origin MS-DOS .NET (2006)
What goes through the pipe Text Objects
Prompt C:\> PS C:\>
Reach Basic commands and .bat The whole system: registry, services, WMI/CIM, network, AD
Version Just one 5.1 (ships with Windows) and 7 (cross-platform, installed separately, binary pwsh)

The .exe programs you use in CMD (ipconfig, whoami, net user…) work the same inside PowerShell. The built-in commands of cmd.exe don’t: dir /s, set, where or mklink are either aliases for cmdlets with a different syntax or don’t exist at all (for those, use cmd /c …). And cmdlets only exist in PowerShell.

PowerShell commands are called cmdlets and always take the form Verb-Noun. The verb comes from a closed list (Get reads, Set changes, New creates, Remove deletes, Start/Stop…), so you can guess names: if Get-Service lists services, Stop-Service stops them.

To Cmdlet
Find a command by keyword Get-Command *firewall*
Every verb for a noun Get-Command -Noun Service
Help with examples Get-Help Get-Process -Examples
What an alias points to Get-Alias ls
Linux CMD PowerShell
ls dir Get-ChildItem
cd · pwd cd · cd Set-Location · Get-Location
cat type Get-Content
cp · mv · rm copy · move · del Copy-Item · Move-Item · Remove-Item
grep findstr Select-String
which where Get-Command
ps · kill tasklist · taskkill Get-Process · Stop-Process
man command /? Get-Help
tail -f — Get-Content -Tail 10 -Wait
env set Get-ChildItem env:

Shared by all of them: whoami, hostname, ping, nslookup, arp -a, netstat and, since Windows 10 (version 1803), ssh, scp, curl.exe and tar.

In Bash, ps aux | grep root filters lines of text, and if the output format changes, the filter breaks. In PowerShell what travels through | are objects with properties, and you filter by property name.

Get-Member tells you which properties an object has:

Ventana de terminal
PS C:\> Get-ChildItem C:\Windows\notepad.exe | Get-Member -MemberType Property
TypeName: System.IO.FileInfo
Name MemberType Definition
---- ---------- ----------
FullName Property string FullName {get;}
LastWriteTime Property datetime LastWriteTime {get;set;}
Length Property long Length {get;}
...

Now you know what you can ask for. The three pieces you’ll use the most:

Cmdlet Does Example
Where-Object Filters Where-Object Length -gt 1MB
Select-Object Picks properties or the first N Select-Object Name, Length -First 5
Sort-Object Sorts Sort-Object LastWriteTime -Descending

Comparison operators are words: -eq, -ne, -gt, -lt, -like (wildcards) and -match (regular expression). You don’t use > because > redirects to a file, just like in Bash.

  • Variables start with $ and hold objects, not text: $procs = Get-Process.
  • Inside Where-Object and ForEach-Object, $_ is the object currently going through the pipeline.
  • A script is a .ps1 file and you run it by its path: .\script.ps1 (the .\ is mandatory).
Ventana de terminal
foreach ($svc in Get-Service) {
if ($svc.Status -eq 'Running') { $svc.Name }
}
# the same in one line
Get-Service | Where-Object { $_.Status -eq 'Running' } | ForEach-Object { $_.Name }

It decides whether PowerShell runs .ps1 scripts. The default is Restricted (none) on Windows 10 and 11 and RemoteSigned on Windows Server (scripts downloaded from the internet must be signed).

  • Get-ExecutionPolicy -List shows it per scope.
  • powershell -ExecutionPolicy Bypass -File .\script.ps1 skips it for that run, no admin rights needed, unless the policy is enforced by GPO (the MachinePolicy and UserPolicy scopes take precedence over the parameter).

Microsoft says it plainly: it is not a security boundary, just a safeguard against running something by accident. Even with a GPO in place, a script’s contents can still be read and run other ways (for example, by piping them to Invoke-Expression).

Get-History only shows the current session. But the PSReadLine module saves to disk almost everything that gets typed, across all sessions (up to 4096 lines by default). Recent PSReadLine versions, such as the one in PowerShell 7, skip lines containing password, token, secret, apikey or asplaintext; the one bundled with Windows PowerShell 5.1 is older:

Ventana de terminal
PS C:\> (Get-PSReadLineOption).HistorySavePath
C:\Users\ana\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

Windows ends lines with CRLF (\r\n); Linux uses only LF. A Bash script saved on Windows fails on Kali with nonsense errors such as $'\r': command not found. Fix it with dos2unix script.sh (or sed -i 's/\r$//' script.sh).

Ventana de terminal
# Discover without leaving the console
PS C:\> Get-Command *process* # which cmdlets mention "process"?
PS C:\> Get-Help Stop-Process -Examples # usage examples
PS C:\> Get-Alias curl # in 5.1: curl -> Invoke-WebRequest
# Top 5 processes by memory
PS C:\> Get-Process | Sort-Object WS -Descending | Select-Object -First 5 Name, Id, WS
# WS = Working Set, memory in bytes
# Files modified in the last week under the profile
PS C:\> Get-ChildItem $env:USERPROFILE -Recurse -File -ErrorAction SilentlyContinue |
>> Where-Object LastWriteTime -gt (Get-Date).AddDays(-7) |
>> Select-Object FullName, LastWriteTime
# -ErrorAction SilentlyContinue hides the "access denied" noise
Ventana de terminal
# Search text in files (PowerShell's grep -ri)
PS C:\> Get-ChildItem C:\inetpub -Recurse -Include *.config, *.xml -ErrorAction SilentlyContinue |
>> Select-String -Pattern 'password' |
>> Select-Object Path, LineNumber, Line
# Returns file, line number and the matching line
Ventana de terminal
:: The same in CMD
C:\> dir /s /b C:\inetpub\*.config
C:\> findstr /s /i /n "password" C:\inetpub\*.config
:: /s subfolders · /i case-insensitive · /n line number
Ventana de terminal
# Current user's PowerShell history
PS C:\> Get-Content (Get-PSReadLineOption).HistorySavePath -Tail 20
# Running a script while the policy is Restricted
PS C:\> .\enum.ps1
# .\enum.ps1 cannot be loaded because running scripts is disabled on this system.
PS C:\> powershell -ExecutionPolicy Bypass -File .\enum.ps1
Concept What to remember
CMD · PowerShell Text · objects. .exe programs work in both; CMD built-ins don’t.
Verb-Noun Get reads, Set changes, New creates, Remove deletes.
Get-Command *word* Find the cmdlet you need.
Get-Help -Examples man with examples.
| Get-Member Which properties the pipeline object has.
Where · Select · Sort Filter · pick · sort.
-gt, not > > is redirection.
$_ The current object inside Where-Object and ForEach-Object.
.\script.ps1 The .\ is mandatory.
Execution Policy Not security. -ExecutionPolicy Bypass.
HistorySavePath History of every session: look for passwords.
sc · curl Trap aliases in PowerShell 5.1: use sc.exe and curl.exe.
CRLF dos2unix before running it on Linux.
  1. What is the fundamental difference between the Bash pipeline and the PowerShell pipeline?

    Answer

    In Bash, lines of text flow through it and you filter by cutting text (grep, cut, awk), which breaks if the format changes. In PowerShell, objects with properties flow through it and you filter by property name (Where-Object Length -gt 1MB), regardless of how they are displayed.

  2. You type sc query in PowerShell and it doesn’t list any services. Why, and how do you fix it?

    Answer

    Because in Windows PowerShell 5.1 sc is the alias for Set-Content (PowerShell 7 removed it). Type sc.exe query instead (or use Get-Service), which works in both.

  3. You want the processes using more than 100 MB of memory. How do you write it, and why not > 100MB?

    Answer

    Get-Process | Where-Object WS -gt 100MB. You don’t use > because in PowerShell, as in Bash, > redirects output to a file: you would create a file named 100MB.

  4. You don’t know which properties Get-Service returns. How do you find out?

    Answer

    Get-Service | Get-Member (or Get-Service | Select-Object -First 1 | Format-List * to also see the values).

  5. A .ps1 script won’t run because “running scripts is disabled”. Does that stop you during a pentest?

    Answer

    No. Execution Policy isn’t a security boundary: powershell -ExecutionPolicy Bypass -File .\script.ps1 skips it for that run without admin rights. If the policy is enforced by GPO the parameter isn’t enough, but the script’s contents can still be run other ways.

  6. Why isn’t Get-History enough to review what a user has typed?

    Answer

    Because it only shows the current session. The history of every session is saved by PSReadLine in the file given by (Get-PSReadLineOption).HistorySavePath, usually ConsoleHost_history.txt under AppData\Roaming.

  7. You copy a Bash script from Windows to your Kali and it fails with $'\r': command not found. What happened?

    Answer

    The file has Windows line endings (CRLF) and Bash reads the \r as part of the commands. Fix it with dos2unix script.sh.