Use this when running classic Windows commands, batch files or tools that expect cmd.exe rather than PowerShell.
Command Prompt
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.
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.
cmd.exe parses the line → expands %vars% → finds the command → runs → ERRORLEVEL set
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
cmd.exePrimary Commands
Configuration and operational commands for this Topic.
cmd.exeReferenceStart the Windows Command Prompt.
Windows / Windows Server / PowerShell · mixedFORReferenceLoop over files or values in a Command Prompt script.
Windows / Windows Server / PowerShell · mixedIFReferenceConditional statement in a Command Prompt script.
Windows / Windows Server / PowerShell · mixedSETReferenceDisplay or set environment variables in Command Prompt.
Windows / Windows Server / PowerShell · mixedSubtopics
Go one level deeper into this subject.
Environment variables hold settings like PATH, TEMP and USERNAME for processes.
Subtopic PipesPipes (|) send one command's output into another's input in cmd, such as ipconfig /all | findstr IPv4 or netstat -ano | find "443", to filter or chain results.
Subtopic RedirectionRedirection sends command output or input to files: > overwrites, >> appends, 2> redirects errors, 2>&1 merges errors with output, and < reads input from a file, such as dir > list.txt 2>&1.
Subtopic Batch FilesBatch files (.bat or .cmd) are scripts of cmd commands with variables, IF, FOR loops, GOTO and CALL.
Subtopic CMD TroubleshootingTroubleshoot cmd and batch scripts with echo on, checking %ERRORLEVEL% after each command, quoting paths with spaces, enabling delayed expansion (!var!) inside loops and running as the right user or elevated.
- cmd passes text, PowerShell passes objects.
- %ERRORLEVEL% only reflects the last command.
- Quote paths with spaces.
echo %PATH%— PATH in CMDset— environment variableswhere <name>— command resolutionecho %ERRORLEVEL%— exit code
ReferenceImportant terms & boundaries2 sections · depth on demand
Useful variables
| Variable | Value |
|---|---|
%ERRORLEVEL% | Exit code of last command |
%CD% | Current directory |
%DATE%, %TIME% | Locale-dependent date/time |
%COMPUTERNAME%, %USERNAME%, %USERDOMAIN% | Identity |
%~dp0 | Folder 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.
| Task | cmd |
|---|---|
| Environment | set, set PATH=%PATH%;C:\Tools, setx (persistent) |
| Command lookup | where robocopy |
| Conditional chaining | cmd1 && cmd2 (on success), cmd1 \|\| cmd2 (on failure) |
| Exit codes | echo %ERRORLEVEL% |
| Delayed expansion | setlocal EnableDelayedExpansion + !var! |
From PowerShell, call cmd built-ins via cmd /c dir /a; quoting rules differ between the two shells.
ReferenceConfiguration & state1 section · depth on demand
Essential commands
| Task | Command |
|---|---|
| Network | ipconfig /all, ping, tracert, nslookup, netstat -ano |
| System | systeminfo, hostname, whoami /all, tasklist, taskkill |
| Files | dir, copy, robocopy, xcopy, attrib, icacls |
| Disks | diskpart, chkdsk, fsutil |
| Services | sc query, net start/stop |
| Policy | gpupdate /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
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
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%