15 Must-Know Windows PowerShell Commands for Junior Systems Engineers
1. Get-Help
The Get-Help
cmdlet is your best friend when learning about PowerShell commands. It provides detailed documentation, parameter descriptions, and usage examples directly in your console.
Example: To view detailed help for the Get-Service
cmdlet, run:
Get-Help Get-Service -Detailed
You can also see just the examples:
Get-Help Get-Service -Examples
Tip: Update your help files regularly by running Update-Help
(as an administrator) to get the latest documentation.
2. Get-Command
Get-Command
is the discovery tool in PowerShell. It lists all available commands (cmdlets, functions, workflows, aliases) so you can quickly find the right one for your task.
Example: Find all commands that include the word “service”:
Get-Command *service*
To see all commands available from a specific module, such as Microsoft.PowerShell.Management:
Get-Command -Module Microsoft.PowerShell.Management
3. Get-Service
Use Get-Service
to quickly display the status of all services running on a Windows system. This is useful for monitoring system health and troubleshooting.
Example: List all services:
Get-Service
Filtering Example: List only services that are currently running:
Get-Service | Where-Object { $_.Status -eq 'Running' }
This command is especially handy when you need a snapshot of your system’s service status before performing maintenance.
4. Start-Service
The Start-Service
cmdlet is used to start a service that is stopped. It is perfect for automating service startup during system maintenance or after a reboot.
Example: Start the Windows Update service:
Start-Service -Name "wuauserv"
Tip: Always verify the service’s status before and after running this command using Get-Service
.
5. Stop-Service
The Stop-Service
cmdlet stops a running service. This is often used during troubleshooting or when you need to safely stop a service for configuration changes.
Example: Stop the Windows Update service:
Stop-Service -Name "wuauserv"
Warning: Ensure that stopping the service won’t negatively affect other system operations.
6. Restart-Service
Sometimes a service needs a quick refresh, and Restart-Service
provides a simple way to stop and then start a service in one step.
Example: Restart the Windows Update service:
Restart-Service -Name "wuauserv"
Advanced Example: Restart only if the service is running:
$service = Get-Service -Name "wuauserv"
if ($service.Status -eq "Running") {
Restart-Service -InputObject $service
} else {
Write-Output "Service is not running."
}
7. Get-Process
The Get-Process
cmdlet provides a snapshot of all running processes on your machine. It’s essential for performance monitoring and identifying resource-hogging applications.
Example: Display all active processes:
Get-Process
Filtering Example: Show only processes named notepad
:
Get-Process -Name "notepad"
8. Stop-Process
When a process becomes unresponsive or consumes too many resources, Stop-Process
allows you to terminate it safely. Use the -Force
parameter if necessary.
Example: Force-stop the notepad
process:
Stop-Process -Name "notepad" -Force
Note: Use this command carefully, as terminating processes abruptly can cause data loss or system instability.
9. Get-EventLog
Get-EventLog
lets you query Windows event logs to diagnose issues or monitor system activity. It supports filtering by log name, event ID, and more.
Example: Retrieve the 50 most recent entries from the Application log:
Get-EventLog -LogName Application -Newest 50
Advanced Example: Filter events by a specific event ID (e.g., 1074, which indicates system shutdowns/restarts):
Get-EventLog -LogName System -InstanceId 1074
10. Get-ChildItem
Similar to dir
on Command Prompt or ls
on Unix/Linux, Get-ChildItem
lists files and directories. It’s the cornerstone for navigating and managing your file system.
Example: List everything in C:\Users
:
Get-ChildItem -Path C:\Users
Filtering Example: List only directories in the same path:
Get-ChildItem -Path C:\Users -Directory
11. New-Item
The New-Item
cmdlet creates new files, folders, or other objects. It’s incredibly useful when you need to automate the creation of directories or configuration files.
Example: Create a new directory in C:\Temp
:
New-Item -Path "C:\Temp\NewFolder" -ItemType Directory
Additional Example: Create a new text file with initial content:
New-Item -Path "C:\Temp\example.txt" -ItemType File -Value "Hello, PowerShell!"
12. Remove-Item
The Remove-Item
cmdlet deletes files, folders, or other objects from your system. Since it permanently removes items, always double-check the target path.
Example: Delete a file:
Remove-Item -Path "C:\Temp\OldFile.txt"
Recursive Example: Delete a directory and all its contents:
Remove-Item -Path "C:\Temp\OldFolder" -Recurse
Tip: Consider using the -WhatIf
parameter first to simulate the deletion without actually removing any files.
13. Set-ExecutionPolicy
PowerShell’s script execution policy helps protect your system from running untrusted scripts. Use Set-ExecutionPolicy
to modify these settings safely.
Example: Change the policy to RemoteSigned
for the current user:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Explanation: With RemoteSigned
, local scripts run without a signature, but any downloaded scripts must be signed by a trusted publisher.
14. Invoke-Command
Managing multiple systems? Invoke-Command
lets you run commands on remote computers. It is a powerful tool for centralized administration and automation across a network.
Example: Execute Get-Service
on a remote machine named Server01
:
Invoke-Command -ComputerName Server01 -ScriptBlock { Get-Service }
Advanced Example: Run a process-monitoring command on multiple servers:
$servers = @("Server01", "Server02", "Server03")
Invoke-Command -ComputerName $servers -ScriptBlock {
Get-Process | Where-Object { $_.CPU -gt 100 }
}
Note: Ensure PowerShell remoting is enabled on the target machines using Enable-PSRemoting
.
15. Export-CSV
Finally, Export-CSV
helps you convert command output into CSV files, which is ideal for reporting, logging, or further data analysis in tools like Excel.
Example: Export the list of running processes to a CSV file:
Get-Process | Export-CSV -Path "C:\Temp\Processes.csv" -NoTypeInformation
Explanation: The -NoTypeInformation
parameter prevents PowerShell from including extra type metadata in your CSV file, resulting in a cleaner export.