728x90 AdSpace

space
Win Dogecoins for Posting Unique self written article about any type of subject. Terms and conditions apply.
For best Article Prize= 100 dogecoins

temporary posting address amir.shin74.576576cfghfjf@blogger.com

Latest

Tuesday, 15 July 2025

The PowerShell Cheat Sheet for Beginners

 



Ready to unlock the true power of your Windows machine? Forget clicking through endless menus and start automating your workflow with PowerShell! This is not your average cheat sheet; it's a comprehensive guide packed with detailed explanations and practical examples to get you comfortable with the command line.

PowerShell is more than just a command prompt—it's a powerful scripting environment built on the .NET framework. Every command, or "cmdlet" (command-let), works with objects, not just text, which gives you incredible flexibility and control.

Let's dive in!


Part 1: File System Navigation & Management 📂

The foundation of any command-line work is moving around and managing your files.

  • Get-Location (Alias: gl, pwd): The most basic command. It tells you exactly where you are in the file system.

    Get-Location
    

    Example Output: C:\Users\YourUser

  • Set-Location (Alias: sl, cd): Moves you to a new directory. You can use full paths or relative paths.

    # Change to the 'Program Files' directory
    Set-Location "C:\Program Files"
    

    Go up one level from your current location

    Set-Location ..

    Navigate into a sub-folder

    Set-Location MyProject\SourceFiles

  • Get-ChildItem (Alias: gci, dir, ls): Lists the contents of a directory.

    # List all files and folders in the current directory
    Get-ChildItem
    

    List all files and folders, including hidden items

    Get-ChildItem -Force

    List only files ending with .txt

    Get-ChildItem -Path C:\MyDocuments -Filter *.txt


Part 2: Working with Files & Content ✍️

PowerShell is fantastic for creating, moving, and editing files.

  • New-Item: Creates a new file or folder.

    # Create a new folder named 'Reports'
    New-Item -Path "C:\Data" -Name "Reports" -ItemType Directory
    

    Create a new text file named 'log.txt'

    New-Item -Path "C:\Data\Reports" -Name "log.txt" -ItemType File

  • Copy-Item: Copies files or folders from one location to another.

    # Copy a file
    Copy-Item -Path "C:\Data\log.txt" -Destination "C:\Backup\log.txt"
    

    Copy a folder and its contents

    Copy-Item -Path "C:\Data" -Destination "C:\Backup" -Recurse

  • Move-Item: Moves a file or folder.

    # Move the 'log.txt' file
    Move-Item -Path "C:\Data\log.txt" -Destination "C:\Data\Reports"
    
  • Remove-Item: Deletes files and folders. Be careful!

    # Delete a single file
    Remove-Item -Path "C:\Data\log.txt"
    

    Delete a folder and all its contents

    Remove-Item -Path "C:\Data\OldReports" -Recurse -Force

  • Get-Content (Alias: cat): Reads the content of a file.

    Get-Content -Path "C:\Data\log.txt"
    
  • Set-Content: Overwrites the content of a file.

    Set-Content -Path "C:\Data\notes.txt" -Value "This is my new note."
    
  • Add-Content: Appends content to an existing file.

    Add-Content -Path "C:\Data\notes.txt" -Value "`nAnother line of text."
    

Part 3: System, Process, and Service Management ⚙️

This is where PowerShell's true power shines. You can manage your entire computer from a single prompt.

  • Get-Process: Lists all running processes.

    # Get all running processes
    Get-Process
    

    Get a specific process by name (e.g., notepad)

    Get-Process -Name notepad

    Get the 5 processes using the most CPU

    Get-Process | Sort-Object -Property CPU -Descending | Select-Object -First 5

  • Stop-Process: Stops a running process by name or ID.

    # Forcefully stop the notepad process
    Stop-Process -Name notepad -Force
    
  • Get-Service: Lists all services on your computer.

    # Get all services that are currently running
    Get-Service | Where-Object { $_.Status -eq 'Running' }
    

    Get a service by name and show its status

    Get-Service -Name "Spooler"

  • Start-Service, Stop-Service, Restart-Service: Manages the state of a service.

    # Stop and then start the Spooler service
    Stop-Service -Name "Spooler"
    Start-Service -Name "Spooler"
    

Part 4: The Power of the Pipeline (|)

This is the most crucial concept in PowerShell. The pipeline takes the output of one command and sends it as the input to the next.

  • Select-Object (Alias: select): Chooses specific properties from the objects you are working with.

    # Get all services, but only show their Name, Status, and DisplayName
    Get-Service | Select-Object Name, Status, DisplayName
    
  • Where-Object (Alias: where): Filters objects based on specific criteria.

    # Find all services whose name starts with 'W'
    Get-Service | Where-Object { $_.Name -like "W*" }
    

    Find all running processes that are using more than 100 MB of memory

    Get-Process | Where-Object { $_.WS -gt 100MB }

Part 5: User & Network Management 🖥️

  • Get-LocalUser: Lists local user accounts on your machine.

    Get-LocalUser
    
  • Get-LocalGroup: Lists local security groups.

    Get-LocalGroup
    
  • Test-Connection (Alias: ping): Sends ICMP echo requests to test network connectivity.

    # Ping google.com four times
    Test-Connection -ComputerName google.com -Count 4
    
  • Get-NetIPConfiguration: Displays network configuration details like IP address, DNS servers, etc.

    Get-NetIPConfiguration
    

Essential Learning Tools & Tips 💡

  • Get-Help: This is your best friend. Use it to learn about any cmdlet.

    Get-Help Get-ChildItem -Examples  # Shows practical examples
    Get-Help Get-Process -Full      # Shows full details and all parameters
    
  • Show-Command: A graphical tool that helps you build a command.

    Show-Command Get-Service
    

This cheat sheet is just the beginning. The more you practice, the more powerful you'll become. The next time you have a repetitive task, think about how you can use PowerShell to automate it.

The PowerShell Cheat Sheet for Beginners
  • Blogger Comments
  • Facebook Comments

0 comments :

Post a Comment

Post your valuable comments.

//]]> Top