Top 20 PowerShell and Command Prompt Commands for Common Tasks

PowerShell and Command Prompt (cmd) are powerful tools in Windows that help users automate and execute various administrative tasks efficiently. Whether you need to map network drives, configure IP settings, or troubleshoot system issues, these command-line tools can save time and effort. Here are the top 20 PowerShell and Command Prompt commands for common tasks.

1. Map a Network Drive

Command Prompt:

net use Z: \\server\share /persistent:yes

PowerShell:

New-PSDrive -Name Z -PSProvider FileSystem -Root \\server\share -Persist

2. Disconnect a Network Drive

Command Prompt:

net use Z: /delete

PowerShell:

Remove-PSDrive -Name Z -Force

3. Set a Static IP Address

Command Prompt:

netsh interface ip set address name="Ethernet" static 192.168.1.100 255.255.255.0 192.168.1.1

PowerShell:

New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 192.168.1.100 -PrefixLength 24 -DefaultGateway 192.168.1.1

4. Set the Adapter to DHCP

Command Prompt:

netsh interface ip set address name="Ethernet" source=dhcp

PowerShell:

Set-NetIPInterface -InterfaceAlias "Ethernet" -Dhcp Enabled

5. Display Network Configuration

Command Prompt:

ipconfig /all

PowerShell:

Get-NetIPConfiguration

6. Flush DNS Cache

Command Prompt:

ipconfig /flushdns

PowerShell:

Clear-DnsClientCache

7. Restart Network Adapter

Command Prompt:

netsh interface set interface "Ethernet" admin=disable
netsh interface set interface "Ethernet" admin=enable

PowerShell:

Disable-NetAdapter -Name "Ethernet" -Confirm:$false
Enable-NetAdapter -Name "Ethernet" -Confirm:$false

8. Check Open Network Ports

Command Prompt:

netstat -an

PowerShell:

Get-NetTCPConnection | Select-Object LocalPort, RemotePort, State

9. Test Network Connectivity

Command Prompt:

ping google.com

PowerShell:

Test-NetConnection -ComputerName google.com

10. Display Active Network Connections

Command Prompt:

netstat -ano

PowerShell:

Get-NetTCPConnection

11. Restart a Computer

Command Prompt:

shutdown /r /t 0

PowerShell:

Restart-Computer -Force

12. Shutdown a Computer

Command Prompt:

shutdown /s /t 0

PowerShell:

Stop-Computer -Force

13. View System Information

Command Prompt:

systeminfo

PowerShell:

Get-ComputerInfo

14. Get List of Installed Programs

Command Prompt:

wmic product get name,version

PowerShell:

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion

15. List Running Processes

Command Prompt:

tasklist

PowerShell:

Get-Process

16. Kill a Process

Command Prompt:

taskkill /IM notepad.exe /F

PowerShell:

Stop-Process -Name notepad -Force

17. Get Disk Space Information

Command Prompt:

wmic logicaldisk get name, size, freespace

PowerShell:

Get-PSDrive -PSProvider FileSystem

18. Create a New User Account

Command Prompt:

net user Username Password /add

PowerShell:

New-LocalUser -Name "Username" -Password (ConvertTo-SecureString "Password" -AsPlainText -Force) -FullName "New User" -Description "New User Account"

19. Add User to Administrators Group

Command Prompt:

net localgroup Administrators Username /add

PowerShell:

Add-LocalGroupMember -Group "Administrators" -Member "Username"

20. Check Windows Activation Status

Command Prompt:

slmgr /xpr

PowerShell:

(Get-CimInstance -query "select LicenseStatus from SoftwareLicensingProduct where LicenseStatus=1").LicenseStatus

Conclusion

PowerShell and Command Prompt provide powerful functionalities for performing administrative tasks efficiently. By mastering these commands, you can manage network configurations, troubleshoot system issues, and optimize your Windows environment more effectively. Whether you’re an IT professional or a casual user, these commands can help you save time and effort.