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

CommandPurposeExample
cdChange directorycd C:\Users\John\Documents
cd ..Go up one directorycd ..
dirList directory contentsdir /a (show hidden files)
md / mkdirCreate a directorymd C:\Projects\NewFolder
rd / rmdirRemove a directoryrd C:\Projects\OldFolder /s (/s = including contents)
copyCopy filescopy file.txt D:\Backup\
xcopyExtended copy (subdirectories)xcopy C:\Source D:\Dest /s /e
robocopyRobust copy (best for large/network copies)robocopy C:\Source D:\Dest /mir
moveMove or rename filesmove file.txt D:\NewLocation\
delDelete filesdel file.txt
renRename fileren oldname.txt newname.txt
typeDisplay file contentstype readme.txt
clsClear the screencls

System Commands

CommandPurposeExample
sfc /scannowScan and repair protected system filessfc /scannow (requires Admin)
DISMRepair Windows imageDISM /Online /Cleanup-Image /RestoreHealth
chkdskCheck and repair disk errorschkdsk C: /f /r (/f = fix errors, /r = locate bad sectors)
shutdownShutdown or restartshutdown /s /t 0 (shutdown now), shutdown /r (restart)
tasklistList running processestasklist
taskkillEnd a processtaskkill /PID 1234 /F
systeminfoDisplay system informationsysteminfo
winverDisplay Windows versionwinver
gpupdateRefresh Group Policygpupdate /force
gpresultDisplay applied Group Policygpresult /r

Disk Commands

CommandPurposeNotes
diskpartAdvanced disk management (command-line)Interactive tool; type commands after launch
formatFormat a driveformat D: /FS:NTFS /Q (quick format as NTFS)
convertConvert FAT32 to NTFS (without data loss)convert D: /FS:NTFS

Network Commands (Recap)

CommandPurpose
ipconfigDisplay/manage IP configuration
pingTest connectivity
tracertTrace route to destination
nslookupDNS lookup
netstatDisplay active connections
net userManage user accounts (create, modify, delete)
net shareManage shared folders
net useMap/disconnect network drives
hostnameDisplay computer name

PowerShell

PowerShell is the modern command-line shell and scripting language for Windows:

CmdletEquivalent CMDPurpose
Get-ProcesstasklistList running processes
Stop-ProcesstaskkillEnd a process
Get-Servicenet startList services and their status
Start-Servicenet start [name]Start a service
Stop-Servicenet stop [name]Stop a service
Get-ChildItemdirList directory contents
Copy-ItemcopyCopy files
Remove-Itemdel / rdDelete files or directories
Get-EventLogN/ARead event logs
Get-HelphelpDisplay 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

ToolUse WhenCommand
sfc /scannowSystem files are corrupted or missingsfc /scannow
DISM /RestoreHealthsfc 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