DEV Community

kingyou
kingyou

Posted on

40 Most Useful PowerShell and Command Prompt Commands for Windows

Introduction

Whether you're a system administrator, developer, or power user, mastering command-line tools is essential for efficient Windows management. This comprehensive guide covers 40 of the most useful PowerShell and Command Prompt commands that will boost your productivity and help you troubleshoot issues like a pro.

File and Directory Management

1. dir / ls

Purpose: List directory contents

dir
ls  # PowerShell alias
Enter fullscreen mode Exit fullscreen mode

2. cd

Purpose: Change directory

cd C:\Users\Username\Documents
Enter fullscreen mode Exit fullscreen mode

3. mkdir / md

Purpose: Create a new directory

mkdir NewFolder
Enter fullscreen mode Exit fullscreen mode

4. rmdir / rd

Purpose: Remove a directory

rmdir OldFolder
Enter fullscreen mode Exit fullscreen mode

5. copy / cp

Purpose: Copy files

copy source.txt destination.txt
Copy-Item source.txt destination.txt  # PowerShell
Enter fullscreen mode Exit fullscreen mode

6. move / mv

Purpose: Move or rename files

move oldname.txt newname.txt
Enter fullscreen mode Exit fullscreen mode

7. del / rm

Purpose: Delete files

del file.txt
Remove-Item file.txt  # PowerShell
Enter fullscreen mode Exit fullscreen mode

8. tree

Purpose: Display directory structure

tree /F
Enter fullscreen mode Exit fullscreen mode

System Information

9. systeminfo

Purpose: Display detailed system information

systeminfo
Enter fullscreen mode Exit fullscreen mode

10. Get-ComputerInfo (PowerShell)

Purpose: Get comprehensive computer information

Get-ComputerInfo
Enter fullscreen mode Exit fullscreen mode

11. hostname

Purpose: Display computer name

hostname
Enter fullscreen mode Exit fullscreen mode

12. ver

Purpose: Display Windows version

ver
Enter fullscreen mode Exit fullscreen mode

13. Get-WmiObject (PowerShell)

Purpose: Query system information via WMI

Get-WmiObject Win32_OperatingSystem
Enter fullscreen mode Exit fullscreen mode

Network Commands

14. ipconfig

Purpose: Display network configuration

ipconfig /all
Enter fullscreen mode Exit fullscreen mode

15. ping

Purpose: Test network connectivity

ping google.com
Enter fullscreen mode Exit fullscreen mode

16. tracert

Purpose: Trace route to destination

tracert google.com
Enter fullscreen mode Exit fullscreen mode

17. nslookup

Purpose: Query DNS information

nslookup google.com
Enter fullscreen mode Exit fullscreen mode

18. netstat

Purpose: Display network statistics and connections

netstat -an
Enter fullscreen mode Exit fullscreen mode

19. arp

Purpose: Display ARP cache

arp -a
Enter fullscreen mode Exit fullscreen mode

20. Test-Connection (PowerShell)

Purpose: Advanced ping functionality

Test-Connection -ComputerName google.com -Count 4
Enter fullscreen mode Exit fullscreen mode

21. Invoke-WebRequest (PowerShell)

Purpose: Download files from web

Invoke-WebRequest -Uri "https://example.com/file.zip" -OutFile "file.zip"
Enter fullscreen mode Exit fullscreen mode

Process Management

22. tasklist

Purpose: List running processes

tasklist
Enter fullscreen mode Exit fullscreen mode

23. taskkill

Purpose: Terminate processes

taskkill /IM notepad.exe /F
Enter fullscreen mode Exit fullscreen mode

24. Get-Process (PowerShell)

Purpose: Get detailed process information

Get-Process | Sort-Object CPU -Descending
Enter fullscreen mode Exit fullscreen mode

25. Stop-Process (PowerShell)

Purpose: Stop processes by ID or name

Stop-Process -Name notepad
Enter fullscreen mode Exit fullscreen mode

Disk Management

26. diskpart

Purpose: Disk partition management tool

diskpart
Enter fullscreen mode Exit fullscreen mode

27. chkdsk

Purpose: Check disk for errors

chkdsk C: /F
Enter fullscreen mode Exit fullscreen mode

28. format

Purpose: Format a drive

format D: /FS:NTFS
Enter fullscreen mode Exit fullscreen mode

29. Get-Disk (PowerShell)

Purpose: Get disk information

Get-Disk
Enter fullscreen mode Exit fullscreen mode

30. Get-Volume (PowerShell)

Purpose: Get volume information

Get-Volume
Enter fullscreen mode Exit fullscreen mode

User and Permission Management

31. net user

Purpose: Manage user accounts

net user username /add
Enter fullscreen mode Exit fullscreen mode

32. whoami

Purpose: Display current user

whoami
Enter fullscreen mode Exit fullscreen mode

33. icacls

Purpose: Display or modify file permissions

icacls C:\folder /grant username:F
Enter fullscreen mode Exit fullscreen mode

34. Get-LocalUser (PowerShell)

Purpose: Get local user accounts

Get-LocalUser
Enter fullscreen mode Exit fullscreen mode

Advanced PowerShell Commands

35. Get-Service

Purpose: List and manage services

Get-Service | Where-Object {$_.Status -eq 'Running'}
Enter fullscreen mode Exit fullscreen mode

36. Get-EventLog

Purpose: Retrieve event log entries

Get-EventLog -LogName System -Newest 10
Enter fullscreen mode Exit fullscreen mode

37. Get-Help

Purpose: Get command help

Get-Help Get-Process -Examples
Enter fullscreen mode Exit fullscreen mode

38. Select-Object

Purpose: Select specific properties

Get-Process | Select-Object Name, CPU, Memory
Enter fullscreen mode Exit fullscreen mode

39. Where-Object

Purpose: Filter objects

Get-Process | Where-Object {$_.CPU -gt 100}
Enter fullscreen mode Exit fullscreen mode

40. Export-Csv / Import-Csv

Purpose: Export and import CSV data

Get-Process | Export-Csv processes.csv
$data = Import-Csv processes.csv
Enter fullscreen mode Exit fullscreen mode

Bonus Tips

Command History

  • Press F7 in CMD to see command history
  • Use Get-History in PowerShell

Piping Commands

Combine commands using pipes (|):

Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
Enter fullscreen mode Exit fullscreen mode

Running as Administrator

Many commands require elevated privileges. Right-click Command Prompt or PowerShell and select "Run as administrator."

Conclusion

These 40 commands form the foundation of efficient Windows command-line usage. Whether you're automating tasks, troubleshooting issues, or managing systems, these tools will significantly enhance your workflow. Start by mastering the basics, then gradually incorporate more advanced PowerShell cmdlets into your daily routine.

Happy scripting! 🚀

Top comments (0)