Pcornel
Browse topics
Options
Recent
Favorites
Windows · Technical reference

Command Prompt

Direct answer

Command Prompt (cmd.exe) is the classic Windows command-line shell for built-in commands, batch files, environment variables, pipes and redirection. PowerShell is the more capable modern shell.

When to use this

Use this when running classic Windows commands, batch files or tools that expect cmd.exe rather than PowerShell.

First 30 seconds

1. ver — Windows build.

2. where <cmd> — which executable runs?

3. Run as admin when needed (title shows Administrator).

4. Check %ERRORLEVEL% after commands.

5. Prefer PowerShell for scripting new tasks.

Operational verification

cmd.exe parses the line → expands %vars% → finds the command → runs → ERRORLEVEL set

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Windows execution, automation and observability
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformWindows execution, automation and observability · Windows / Windows Server / PowerShell
Key commandcmd.exe
Scope / prerequisiteUse this when running classic Windows commands, batch files or tools that expect cmd.exe rather than PowerShell.
Reference · 4
What next?2 suggested next steps
Child topics (this level)5
Catalog command links4
Evidence0
On this pageJump to a specific section
Windows command reference

Primary Commands

Configuration and operational commands for this Topic.

Drill down

Subtopics

Go one level deeper into this subject.

Key points
  • cmd passes text, PowerShell passes objects.
  • %ERRORLEVEL% only reflects the last command.
  • Quote paths with spaces.
Key checks
  • echo %PATH% — PATH in CMD
  • set — environment variables
  • where <name> — command resolution
  • echo %ERRORLEVEL% — exit code
ReferenceImportant terms & boundaries2 sections · depth on demand

Useful variables

VariableValue
%ERRORLEVEL%Exit code of last command
%CD%Current directory
%DATE%, %TIME%Locale-dependent date/time
%COMPUTERNAME%, %USERNAME%, %USERDOMAIN%Identity
%~dp0Folder of the running batch file
%TEMP%, %APPDATA%, %PROGRAMDATA%Common folders

In depth

cmd.exe remains useful for legacy scripts, recovery environments (WinRE/WinPE) and tools that only exist as executables.

Taskcmd
Environmentset, set PATH=%PATH%;C:\Tools, setx (persistent)
Command lookupwhere robocopy
Conditional chainingcmd1 && cmd2 (on success), cmd1 \|\| cmd2 (on failure)
Exit codesecho %ERRORLEVEL%
Delayed expansionsetlocal EnableDelayedExpansion + !var!

From PowerShell, call cmd built-ins via cmd /c dir /a; quoting rules differ between the two shells.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
ReferenceConfiguration & state1 section · depth on demand

Essential commands

TaskCommand
Networkipconfig /all, ping, tracert, nslookup, netstat -ano
Systemsysteminfo, hostname, whoami /all, tasklist, taskkill
Filesdir, copy, robocopy, xcopy, attrib, icacls
Disksdiskpart, chkdsk, fsutil
Servicessc query, net start/stop
Policygpupdate /force, gpresult /r

PowerShell is preferred for scripting; cmd remains useful for quick checks and older scripts.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docWindows execution, automation and observability current

Authoritative/upstream documentation reviewed for bounded claims in Command Prompt. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands · confidence 94%
Confirmation

Confirm action

Continue?