Docsity

WINDOWS CMD & POWERSHELL COMMANDS AND THEIR FUNCTIONALITY, Cheat Sheet of Computer science

Toggle sidebar
bg1
Windows command-line quick reference โ€ข Verify command behavior on your Windows version Page 1
WINDOWS CMD & POWERSHELL
Two-page quick reference โ€ข Command functions, examples, networking, and defensive security
1. CMD vs PowerShell
CMD (Command Prompt) is a traditional Windows command interpreter, useful for basic file operations and troubleshooting. PowerShell is
a shell and scripting language that works with structured objects, making it useful for administration, automation, and security investigations.
2. Essential commands
Task CMD PowerShell
Current directory cd Get-Location (or pwd)
List files/folders dir Get-ChildItem (or ls)
Change directory cd C:\\Windows Set-Location C:\\Windows
Create folder mkdir Reports New-Item Reports -ItemType Directory
Copy file copy a.txt b.txt Copy-Item a.txt b.txt
Move / rename move a.txt b.txt Move-Item a.txt b.txt
Delete file del a.txt Remove-Item a.txt
Clear screen cls Clear-Host (or cls)
Show date/time date /t & time /t Get-Date
Show username/PC whoami; hostname whoami; hostname
Help / discover help; command /? Get-Help; Get-Command
Command history doskey /history Get-History
3. Processes and services (PowerShell)
Get-Process โ€” list running processes. Get-Process -Name notepad โ€” find Notepad. Stop-Process -Name notepad โ€” stop it
(save work first).
Get-Service โ€” list services. Get-Service -Name wuauserv โ€” inspect Windows Update service. Get-Service | Where-Object
Status -eq 'Running' โ€” show running services.
Get-ComputerInfo โ€” system information. Get-LocalUser โ€” local user accounts. Get-LocalGroup โ€” local groups.
4. Networking and troubleshooting
Command Function
ipconfig /all Show IP addresses, gateway, DNS, and adapter details (CMD; also runs in PowerShell).
ipconfig /flushdns Clear the local DNS resolver cache.
ping 8.8.8.8 Test basic IP reachability; failure alone does not prove the host is down.
tracert example.com Show the network route (CMD). PowerShell: Test-NetConnection example.com -TraceRoute
nslookup example.com Query DNS for a hostname.
netstat -ano Show connections/listening ports and associated process IDs.
Test-NetConnection example.com -Port 443 PowerShell: test TCP connectivity to HTTPS port 443.
pf2

Partial preview of the text

Download WINDOWS CMD & POWERSHELL COMMANDS AND THEIR FUNCTIONALITY and more Cheat Sheet Computer science in PDF only on Docsity!

Windows command-line quick reference โ€ข Verify command behavior on your Windows version Page 1

WINDOWS CMD & POWERSHELL

Two-page quick reference โ€ข Command functions, examples, networking, and defensive security

1. CMD vs PowerShell

CMD (Command Prompt) is a traditional Windows command interpreter, useful for basic file operations and troubleshooting. PowerShell is a shell and scripting language that works with structured objects, making it useful for administration, automation, and security investigations.

2. Essential commands

Task CMD PowerShell Current directory cd Get-Location (or pwd) List files/folders dir Get-ChildItem (or ls) Change directory cd C:\Windows Set-Location C:\Windows Create folder mkdir Reports New-Item Reports -ItemType Directory Copy file copy a.txt b.txt Copy-Item a.txt b.txt Move / rename move a.txt b.txt Move-Item a.txt b.txt Delete file del a.txt Remove-Item a.txt Clear screen cls Clear-Host (or cls) Show date/time date /t & time /t Get-Date Show username/PC whoami; hostname whoami; hostname Help / discover help; command /? Get-Help; Get-Command Command history doskey /history Get-History

3. Processes and services (PowerShell)

Get-Process โ€” list running processes. Get-Process -Name notepad โ€” find Notepad. Stop-Process -Name notepad โ€” stop it (save work first).

Get-Service โ€” list services. Get-Service -Name wuauserv โ€” inspect Windows Update service. Get-Service | Where-Object Status -eq 'Running' โ€” show running services.

Get-ComputerInfo โ€” system information. Get-LocalUser โ€” local user accounts. Get-LocalGroup โ€” local groups.

4. Networking and troubleshooting

Command Function ipconfig /all Show IP addresses, gateway, DNS, and adapter details (CMD; also runs in PowerShell). ipconfig /flushdns Clear the local DNS resolver cache. ping 8.8.8.8 Test basic IP reachability; failure alone does not prove the host is down. tracert example.com Show the network route (CMD). PowerShell: Test-NetConnection example.com -TraceRoute nslookup example.com Query DNS for a hostname. netstat -ano Show connections/listening ports and associated process IDs. Test-NetConnection example.com -Port 443 PowerShell: test TCP connectivity to HTTPS port 443.

Windows command-line quick reference โ€ข Verify command behavior on your Windows version Page 2

SECURITY, LOGS & AUTOMATION

Page 2 โ€ข Defensive cybersecurity / SOC quick reference

5. Files, searching, and output

Get-ChildItem C:\Logs -Recurse โ€” list files under a folder. Get-ChildItem -Filter .log โ€” find log files in the current folder. Select-String -Path .\.log -Pattern 'failed' โ€” search log text for โ€œfailedโ€.

Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 โ€” show the 10 processes with the highest CPU value. Get-Service | Export-Csv services.csv -NoTypeInformation โ€” export service data to CSV.

command > output.txt writes standard output to a file; command >> output.txt appends output. command1 | command2 passes output to the next command. PowerShell pipelines pass objects; CMD pipelines generally pass text.

6. Windows security investigation commands

Command Function / use whoami /all Show current identity, group memberships, and privileges. net user List local user accounts in CMD; inspect account status with appropriate admin permissions. net accounts Display local password and account policy information. Get-WinEvent -LogName Security -MaxEvents 20 Read recent Security log events; access may require elevated permissions. Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625} -MaxEvents 20

Find recent Windows failed-logon events (Event ID 4625).

Get-FileHash .\sample.exe -Algorithm SHA256 Calculate a file hash for investigation and comparison. Get-AuthenticodeSignature .\sample.exe Check a file's Authenticode signature status. Get-MpComputerStatus Check Microsoft Defender status where the cmdlet/module is available. Get-NetTCPConnection List TCP connections; correlate OwningProcess with Get-Process when investigating.

7. CMD system and disk utilities

Command Function systeminfo Show Windows version, hardware, memory, and update information. tasklist List running processes (CMD). taskkill /PID 1234 /T Terminate a process tree by PID; use carefully and replace 1234 with the real PID. chkdsk Check a disk/file system; repairs may require admin rights and/or restart. sfc /scannow Scan and repair protected Windows system files (run as administrator). DISM /Online /Cleanup-Image /RestoreHealth Repair the Windows component store (run as administrator). shutdown /r /t 0 Restart immediately; save work first.

8. Practical SOC workflow

Example: investigate failed logons. Open PowerShell (preferably as Administrator if access is denied), run the Event ID 4625 query above, then review the timestamp, target account, logon type, workstation/source address if present, and status/substatus fields. Correlate with other logs before concluding an attack occurred. Safety notes: Run commands only on systems you own or are authorized to administer. Some commands require Administrator privileges. Avoid stopping unknown processes, deleting files, changing firewall rules, or disabling security tools without understanding the impact. Event availability depends on audit policy and log retention.