Basic PowerShell Commands
1. What is PowerShell?
PowerShell is a task automation and configuration management framework from Microsoft. It includes a command-line shell and a scripting language designed for system administrators and power users.
2. How do I list all available commands in PowerShell?
Use:
Get-Command
This displays all cmdlets, functions, and scripts available in your session.
3. How do I get help on a command?
Use:
Get-Help <CommandName>
Example:
Get-Help Get-Process -Examples
This shows examples of how to use the command.
4. How do I find running processes?
Use:
Get-Process
This lists all active processes.
5. How do I stop a process?
Use:
Stop-Process -Name notepad
or by process ID:
Stop-Process -Id 1234
6. How do I work with services?
- To list services:
Get-Service
- To start a service:
Start-Service -Name Spooler
- To stop a service:
Stop-Service -Name Spooler
7. How do I manage files and directories?
- List files:
Get-ChildItem
- Create a folder:
New-Item -Path C:\Temp -ItemType Directory
- Copy a file:
Copy-Item C:\file.txt D:\Backup\
- Delete a file:
Remove-Item C:\file.txt
8. How do I read and write text files?
- Read:
Get-Content C:\file.txt
- Write:
Set-Content C:\file.txt "Hello World"
- Append:
Add-Content C:\file.txt "New line"
9. How do I check system information?
- Computer info:
Get-ComputerInfo
- Disk space:
Get-PSDrive
- IP configuration:
Get-NetIPAddress
10. How do I filter and sort output?
- Filter:
Get-Process | Where-Object {$_.CPU -gt 100}
- Sort:
Get-Process | Sort-Object CPU -Descending
11. How do I export results to a file?
- Export to text:
Get-Process | Out-File C:\processes.txt
- Export to CSV:
Get-Service | Export-Csv C:\services.csv -NoTypeInformation
12. How do I run a script in PowerShell?
Save your script as a .ps1
file, then run:
.\script.ps1
Note: You may need to adjust the execution policy with:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
13. How do I find my PowerShell version?
Use:
$PSVersionTable.PSVersion
14. What is the difference between Select-Object
and Format-Table
?
Select-Object
selects data (returns objects you can use further).Format-Table
changes how data looks (for display only).
15. Where can I learn more PowerShell commands?
- Microsoft Docs: https://learn.microsoft.com/powershell
- Built-in help:
Update-Help Get-Help *
Would you like me to make this more beginner-friendly (with simple explanations for non-technical users) or more advanced (with admin-focused tasks like Active Directory, networking, and automation)?