Home ยป Windows PowerShell Basics Cheat Sheet

Windows PowerShell Basics Cheat Sheet

by 7kokcmax71

1. What is PowerShell?

PowerShell is a command-line shell and scripting language designed for system administration and automation on Windows. It extends the capabilities of the traditional Command Prompt (CMD) by adding more powerful scripting and automation features.


2. Opening PowerShell

  • Method 1: Press Win + R, type powershell, and press Enter.
  • Method 2: Search “PowerShell” in the Start Menu.
  • Method 3: Shift + Right Click in any folder โ†’ “Open PowerShell window here”.
  • Run as Admin: Right-click “Windows PowerShell” โ†’ Select Run as Administrator.

3. Basic PowerShell Commands

1. Get Current Directory

Get-Location

2. List Files and Folders

Get-ChildItem

Short Version:

dir

3. Change Directory

Set-Location <path>

Example:

Set-Location C:\Users

Short Version:

cd C:\Users

4. Go to Parent Directory

cd ..

5. Create a New Folder

New-Item -ItemType Directory -Name "NewFolder"

6. Create a New File

New-Item -ItemType File -Name "file.txt"

7. Delete a File or Folder

Remove-Item <filename or foldername>

Force Delete (No Confirm):

Remove-Item <filename> -Force

8. Copy Files and Folders

Copy-Item <source> <destination>

Example:

Copy-Item file.txt D:\Backup\

9. Move Files and Folders

Move-Item <source> <destination>

10. Rename Files or Folders

Rename-Item <oldname> <newname>

4. System Information and Network

1. Get IP Configuration

Get-NetIPAddress

2. Check Network Connection (Ping)

Test-Connection google.com

3. Display Active Connections

Get-NetTCPConnection

4. View Running Processes

Get-Process

5. Kill a Process

Stop-Process -Name notepad

6. System Information

Get-ComputerInfo

7. List Installed Programs

Get-WmiObject -Query "SELECT * FROM Win32_Product"

5. User and System Management

1. List Local Users

Get-LocalUser

2. Create a New User

New-LocalUser -Name "User1" -Password (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force)

3. Delete a User

Remove-LocalUser -Name "User1"

4. Shutdown / Restart

Stop-Computer
Restart-Computer

5. Lock Workstation

rundll32.exe user32.dll, LockWorkStation

6. Schedule a Shutdown (60 sec)

shutdown /s /t 60

6. Managing Services

1. List All Services

Get-Service

2. Stop a Service

Stop-Service -Name "wuauserv"

3. Start a Service

Start-Service -Name "wuauserv"

4. Restart a Service

Restart-Service -Name "Spooler"

7. Managing Disks and Drives

1. Check Disk Space

Get-PSDrive

2. Format a Drive

Format-Volume -DriveLetter D -FileSystem NTFS

3. Check for Disk Errors

chkdsk C:

8. Environment Variables

1. View Environment Variables

Get-ChildItem Env:

2. Set a New Environment Variable

[System.Environment]::SetEnvironmentVariable("MyVariable", "Value", "User")

3. Get Specific Environment Variable

$env:Path

9. File and Text Search

1. Search for Files

Get-ChildItem -Path C:\ -Recurse -Filter "*.txt"

2. Search for Text in Files

Select-String -Path *.txt -Pattern "Error"

10. Compress and Extract Files

1. Zip Files

Compress-Archive -Path file.txt -DestinationPath archive.zip

2. Unzip Files

Expand-Archive -Path archive.zip -DestinationPath C:\Extracted

11. Permissions and Ownership

1. View Folder Permissions

icacls C:\Folder

2. Change Folder Permissions

icacls C:\Folder /grant UserName:(OI)(CI)F

3. Take Ownership of a Folder

takeown /f C:\Folder

12. Advanced Commands

1. Run as Administrator

Start-Process powershell -Verb RunAs

2. Edit the Registry

regedit

3. View Installed Drivers

Get-WmiObject Win32_PnPSignedDriver | Select-Object DeviceName, DriverVersion

13. Useful Shortcuts

Command Description
clear Clear the screen
exit Close PowerShell
cls Clear console output
echo $PSVersionTable Show PowerShell version
hostname Display computer name
Get-Help <command> Show command help
history Show command history
alias List all command aliases

Tips for PowerShell

  • Use Tab to autocomplete commands.
  • Use Ctrl + C to stop running commands.
  • Combine commands with | to pass output between them.

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.