Windows Command Line & PowerShell
Key Takeaways
- The Command Prompt (cmd.exe) uses legacy DOS-style commands, while PowerShell uses cmdlets (verb-noun format like Get-Process) and is more powerful for scripting and automation.
- Essential file commands: cd (change directory), dir (list files), copy/xcopy/robocopy (copy files), del (delete files), md/mkdir (create directory), rd/rmdir (remove directory).
- System repair commands: sfc /scannow (System File Checker — scans and repairs protected system files), DISM (Deployment Image Servicing — repairs the Windows image), chkdsk (checks disk for errors).
- The net commands manage network resources: net user (manage accounts), net share (manage shares), net use (map network drives), and net start/stop (manage services).
- Running a command prompt "as Administrator" (elevated) is required for system-level operations like sfc, DISM, diskpart, and service management.
Last updated: March 2026
Windows Command Line & PowerShell
Command Prompt (cmd.exe) Essentials
File and Directory Commands
| Command | Purpose | Example |
|---|---|---|
| cd | Change directory | cd C:\Users\John\Documents |
| cd .. | Go up one directory | cd .. |
| dir | List directory contents | dir /a (show hidden files) |
| md / mkdir | Create a directory | md C:\Projects\NewFolder |
| rd / rmdir | Remove a directory | rd C:\Projects\OldFolder /s (/s = including contents) |
| copy | Copy files | copy file.txt D:\Backup\ |
| xcopy | Extended copy (subdirectories) | xcopy C:\Source D:\Dest /s /e |
| robocopy | Robust copy (best for large/network copies) | robocopy C:\Source D:\Dest /mir |
| move | Move or rename files | move file.txt D:\NewLocation\ |
| del | Delete files | del file.txt |
| ren | Rename file | ren oldname.txt newname.txt |
| type | Display file contents | type readme.txt |
| cls | Clear the screen | cls |
System Commands
| Command | Purpose | Example |
|---|---|---|
| sfc /scannow | Scan and repair protected system files | sfc /scannow (requires Admin) |
| DISM | Repair Windows image | DISM /Online /Cleanup-Image /RestoreHealth |
| chkdsk | Check and repair disk errors | chkdsk C: /f /r (/f = fix errors, /r = locate bad sectors) |
| shutdown | Shutdown or restart | shutdown /s /t 0 (shutdown now), shutdown /r (restart) |
| tasklist | List running processes | tasklist |
| taskkill | End a process | taskkill /PID 1234 /F |
| systeminfo | Display system information | systeminfo |
| winver | Display Windows version | winver |
| gpupdate | Refresh Group Policy | gpupdate /force |
| gpresult | Display applied Group Policy | gpresult /r |
Disk Commands
| Command | Purpose | Notes |
|---|---|---|
| diskpart | Advanced disk management (command-line) | Interactive tool; type commands after launch |
| format | Format a drive | format D: /FS:NTFS /Q (quick format as NTFS) |
| convert | Convert FAT32 to NTFS (without data loss) | convert D: /FS:NTFS |
Network Commands (Recap)
| Command | Purpose |
|---|---|
| ipconfig | Display/manage IP configuration |
| ping | Test connectivity |
| tracert | Trace route to destination |
| nslookup | DNS lookup |
| netstat | Display active connections |
| net user | Manage user accounts (create, modify, delete) |
| net share | Manage shared folders |
| net use | Map/disconnect network drives |
| hostname | Display computer name |
PowerShell
PowerShell is the modern command-line shell and scripting language for Windows:
| Cmdlet | Equivalent CMD | Purpose |
|---|---|---|
| Get-Process | tasklist | List running processes |
| Stop-Process | taskkill | End a process |
| Get-Service | net start | List services and their status |
| Start-Service | net start [name] | Start a service |
| Stop-Service | net stop [name] | Stop a service |
| Get-ChildItem | dir | List directory contents |
| Copy-Item | copy | Copy files |
| Remove-Item | del / rd | Delete files or directories |
| Get-EventLog | N/A | Read event logs |
| Get-Help | help | Display help for a command |
PowerShell Key Concepts
- Cmdlets follow the Verb-Noun naming convention (Get-Process, Set-Location, Remove-Item)
- Pipeline (|) — Pass output of one command to another:
Get-Process | Sort-Object CPU -Descending - Execution Policy — Controls whether scripts can run:
Set-ExecutionPolicy RemoteSigned - PowerShell is built on .NET Framework and can work with .NET objects
System File Checker (sfc) and DISM
When to Use Each
| Tool | Use When | Command |
|---|---|---|
| sfc /scannow | System files are corrupted or missing | sfc /scannow |
| DISM /RestoreHealth | sfc cannot fix the problem (component store corrupt) | DISM /Online /Cleanup-Image /RestoreHealth |
Recommended order: Run DISM first to repair the component store, then run sfc /scannow to repair system files using the clean component store.
Test Your Knowledge
Which command scans and repairs protected Windows system files?
A
B
C
D
Test Your Knowledge
What PowerShell naming convention do cmdlets follow?
A
B
C
D
Test Your KnowledgeFill in the Blank
The command to check a disk for errors and fix them is: chkdsk C: /__
Type your answer below
Test Your Knowledge
What is the correct order to use DISM and sfc when repairing Windows system files?
A
B
C
D