PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and the associated scripting language. It is built on the .NET framework and is designed to help system administrators automate tasks and manage system configurations more efficiently. The following list encompasses some of the most useful PowerShell commands that can significantly streamline your workflow.
The table below provides a curated list of essential PowerShell commands, each accompanied by a detailed description, category classification, and relevant tags to help you navigate and utilize them effectively.
Name | Command | Description | Category | Hotkey | Icon Path | Use PowerShell | Run as Admin | Tags |
---|---|---|---|---|---|---|---|---|
List All Services |
|
Retrieves a list of all services on the local computer. | System Management | None | icons\services.png | Yes | No | Services, System |
Stop a Service |
|
Stops a specific service by its name. | System Management | None | icons\stop.png | Yes | Yes | Services, System |
Get Help on a Command |
|
Provides detailed help information about a specific PowerShell command. | Learning | None | icons\help.png | Yes | No | Help, Documentation |
List All Commands |
|
Lists all available commands in PowerShell. | Learning | None | icons\list.png | Yes | No | Commands, List |
Export Data to CSV |
|
Exports the output of a command to a CSV file. | Data Management | None | icons\export.png | Yes | No | Export, CSV, Data |
List Directory Contents |
|
Lists the contents of a specified directory. | File Management | None | icons\folder.png | Yes | No | Directory, Files |
Get System Information |
|
Retrieves detailed information about the local computer. | System Management | None | icons\system-info.png | Yes | No | System, Information |
Top 5 CPU Processes |
|
Shows the top 5 CPU processes currently running. | System Management | None | icons\adobe-photoshop-align horizontal centers.png | Yes | No | CPU, Processor, Applications |
Disk Space Overview |
|
Shows an overview of disk space usage across all mounted file system drives. | Storage Management | None | icons\disk-space.png | Yes | No | Disk, Storage, FileSystem |
Network Connection Stats |
|
Displays a count of TCP connections grouped by their state. | Networking | None | icons\network.png | Yes | No | Network, TCP, Connections |
Recent Event Log Errors |
|
Fetches the 10 most recent error events from the System event log. | Logging | None | icons\event-log.png | Yes | Yes | EventLog, Error, System |
List Running Services |
|
Shows all currently running services on the system. | System Management | None | icons\service-running.png | Yes | No | Services, System, Diagnostics |
System Information Overview |
|
Retrieves comprehensive system and operating system properties. | System Management | None | icons\computer-info.png | Yes | No | System, Hardware, Information |
Active Network Connections |
|
Lists all active TCP network connections. | Network Management | None | icons\network-connections.png | Yes | No | Network, Connections, TCP |
Event Log Recent Errors |
|
Retrieves the 20 most recent system error events. | System Diagnostics | None | icons\error-log.png | Yes | No | Logs, Errors, Diagnostics |
Disk Space Usage |
|
Shows disk space usage and percentage of free space. | System Management | None | icons\hard-drive.png | Yes | No | Disk, Storage, Space |
Top 5 Memory Processes |
|
Displays the top 5 processes consuming the most memory. | System Management | None | icons\memory.png | Yes | No | Memory, RAM, Applications |
Restart DHCP Service |
|
Restarts the DHCP service. | Network Management | None | icons\network.png | Yes | Yes | DHCP, Network, Service |
Get CPU Usage for a Process |
|
Displays CPU usage for processes named 'cpu'. | Performance Monitoring | None | icons\cpu-usage.png | Yes | No | CPU, Performance |
List All Files in a Directory Recursively |
|
Lists all files and subdirectories within a specified directory. | File Management | None | icons\folder.png | Yes | No | Files, Directories |
Stop a Process by Name |
|
Stops all instances of a process by its name. | Process Management | None | icons\stop-process.png | Yes | No | Process, Stop |
Check Network Connection |
|
Tests network connectivity to a specific host and port. | Network Management | None | icons\network-connection.png | Yes | No | Network, Connectivity |
Get System Information |
|
Displays detailed system and operating system properties. | System Information | None | icons\system-info.png | Yes | No | System, Info |
List Available PowerShell Commands |
|
Lists all available PowerShell commands. | PowerShell Management | None | icons\powershell-commands.png | Yes | No | PowerShell, Commands |
Beyond the basic commands, PowerShell offers advanced functionalities that can further enhance your system management capabilities. Scripts can be written to perform complex tasks, automate repetitive processes, and integrate with other tools and services.
PowerShell scripts allow you to combine multiple commands and logic to perform intricate tasks. For example, automating the monitoring of system resources, deploying software across multiple machines, or managing user accounts can all be achieved through scripting.
# Example: Automate Service Restart
$services = "DHCP", "W32Time"
foreach ($service in $services) {
Restart-Service -Name $service -Force
Write-Output "$service has been restarted."
}
PowerShell can seamlessly integrate with other Windows tools and third-party applications. This interoperability allows for comprehensive system management and the ability to extend PowerShell's capabilities through modules and add-ons.
Effective error handling ensures that your scripts can gracefully handle unexpected situations, while logging provides a record of actions taken and any issues encountered.
# Example: Error Handling in Scripts
Try {
Stop-Service -Name "NonExistentService" -ErrorAction Stop
} Catch {
Write-Error "Failed to stop service: $_"
}
Adhering to best practices ensures that your use of PowerShell is both effective and secure.
Always be cautious when running scripts from untrusted sources. Use the Get-Help
command to understand what each script does before execution. Additionally, consider implementing execution policies and using digital signatures for your scripts.
Adopting consistent naming conventions for your scripts and functions makes them easier to understand and maintain. This practice is especially beneficial in collaborative environments.
Well-documented scripts with clear comments enhance readability and facilitate easier troubleshooting and updates.
# Example: Documenting a Script
<#
.SYNOPSIS
Restarts specified services.
.DESCRIPTION
This script restarts a list of services provided in the $services array.
.PARAMETER None
.EXAMPLE
./Restart-Services.ps1
#>
$services = "DHCP", "W32Time"
foreach ($service in $services) {
Restart-Service -Name $service -Force
Write-Output "$service has been restarted."
}
PowerShell is an indispensable tool for system administrators, offering a vast array of commands that simplify and automate complex tasks. By mastering these essential commands and adhering to best practices, you can significantly enhance your efficiency and effectiveness in managing Windows environments.