Applies to: Command Prompt (cmd.exe) on Windows Server 2016 to 2025 and Windows 10 and 11 (syntax from Microsoft’s Windows commands reference; PowerShell aliases checked in PowerShell 7.4)
These are the Command Prompt commands you will use most on a Windows server, grouped by task. For anything that changes the system, open Command Prompt as administrator: right-click Command Prompt in the Start menu and select Run as administrator. Add /? to any command to see its help, for example ipconfig /?.
Run them in Command Prompt. PowerShell also runs the separate tools such as ipconfig, netstat and robocopy, but there dir, del, copy, move, ren and type are aliases for PowerShell cmdlets (for example del is Remove-Item), so options like /a or /q don’t work. Microsoft recommends PowerShell for new automation: see PowerShell commands for Windows servers.
System information
hostname: the computer name.whoami: the account you are logged in with.systeminfo: operating system configuration, product ID and hardware such as RAM, disk space and network cards.ver: the Windows version number.
Network
ipconfig ipconfig /all ipconfig /flushdns ping 203.0.113.10 tracert example.com pathping example.com nslookup example.com netstat -ano netstat -ano | findstr :3389 route print
ipconfigshows the IPv4 and IPv6 addresses, subnet mask and default gateway;/alladds DNS servers and more;/flushdnsempties the DNS client cache.tracertlists each hop to a host;pathpingalso measures packet loss per hop.netstat -ano:-ashows all connections and listening ports,-nnumbers instead of names,-othe process ID (PID). Pipe it tofindstrto find one port.route printshows the routing table, the same asnetstat -r.
Processes and services
tasklist tasklist /fi "IMAGENAME eq w3wp.exe" tasklist /fi "PID eq 1234" tasklist /svc taskkill /pid 1234 taskkill /pid 1234 /t taskkill /im notepad.exe /f sc.exe query state= all sc.exe query wuauserv
tasklist /svcshows which services run inside each process.taskkill /talso ends the child processes;/fends the process by force.sc.exe query state= alllists running and stopped services. Keep the space afterstate=: according to Microsoft the command fails without it.
To find what is using a port: netstat -ano | findstr :80, take the PID from the last column, then tasklist /fi "PID eq 1234".
Files and folders
dir /a cd /d D:\sites mkdir D:\backup\sites copy web.config web.config.bak move report.txt D:\archive\ ren old.txt new.txt type C:\logs\app.log findstr /s /i /n "connectionString" *.config tree D:\sites del /q *.tmp rmdir /s /q D:\old-site
dir /aincludes hidden and system files;cd /dchanges the drive as well as the folder.findstr /s /i /nsearches subfolders too, ignores case and prints line numbers.del /qdoesn’t ask for confirmation, and Microsoft warns that files deleted withdelcan’t be retrieved. Rundirwith the same wildcard first.rmdir /s /qdeletes a folder with everything in it, without asking. It can’t delete the folder you are currently in.
Copy large folders with robocopy
robocopy C:\sites D:\backup\sites /e /z /r:2 /w:5 /log:C:\logs\backup.log robocopy C:\sites D:\mirror\sites /mir /r:2 /w:5 /log:C:\logs\mirror.log
/ecopies subfolders, including empty ones;/zcan resume an interrupted file./mirmakes the destination an exact copy and deletes files there that are not in the source.- Always set
/rand/w: by default robocopy retries a failed file 1,000,000 times, 30 seconds apart. - Exit codes below 8 mean no failures (1 = files copied); 8 or higher means at least one file failed.
Users
net user net user alice net user alice * /add net user alice /active:no net user alice /delete
With * in place of a password, Windows prompts for it and doesn’t show it as you type.
Repair, restart and shut down
sfc /scannow chkdsk C: shutdown /r /t 0 shutdown /r /t 300 /c "Installing updates" shutdown /a shutdown /s /t 0
sfc /scannowchecks protected system files and repairs them where possible (administrators only).chkdsk C:without/fonly reports; with/fon the system drive it offers to run at the next restart, because the volume is in use.shutdown /rrestarts,/tsets the delay in seconds (default 30),/cadds a message and/acancels a pending shutdown. According to Microsoft, any delay above 0 also implies/f, which closes programs without warning.- On a remote server use
shutdown /r, not/s: after a full shutdown you need the control panel or console to power it on again.
Outdated commands
wmic is deprecated; Microsoft says it is superseded by Windows PowerShell for WMI.
Related: change the Remote Desktop port and flush the DNS cache. Running Windows in the cloud: Windows VPS, with the Windows Server licence included.
Official documentation: Microsoft: Windows commands reference.
Ucartz services for this topic
- Hire an expert: engineers per 15 minutes, per hour or per month, with no contract.
- Server management: on-demand administration, hardening, migrations and monitoring.
