Skip to main content
    Courses/PowerShell/Introduction to PowerShell

    Lesson 1 • Beginner

    Introduction to PowerShell ⚡

    By the end of this lesson you'll understand what makes PowerShell special — it pipes objects, not text — read and write your first Verb-Noun cmdlets, and use Get-Help and Get-Command to teach yourself any command you'll ever need.

    What You'll Learn

    • What PowerShell is: an object-oriented, cross-platform shell
    • Why the pipeline passes objects, not plain text like bash
    • The Verb-Noun naming convention that makes cmdlets predictable
    • Run your first cmdlets: Write-Output, Get-Date, Get-Process
    • Discover any command with Get-Command and Get-Help
    • Avoid the execution-policy trap that blocks beginners' scripts

    Real-World Analogy

    Think of an old shell like bash as handing you a printed newspaper: you get a wall of text, and to find one fact you scan and cut out the right words by hand. PowerShell hands you a spreadsheet instead — rows, columns, and labelled cells. To get the busiest process you don't slice text; you simply say "sort by the CPU column and give me the top 3". Because PowerShell moves real objects (data with named properties) between commands rather than raw text, you ask for things by name — and your commands stop breaking the moment a layout changes.

    1. What PowerShell Is (and Your First Cmdlets)

    PowerShell is Microsoft's object-oriented, cross-platform shell and scripting language. A shell is a program that runs commands you type; "object-oriented" means each command hands back structured data (built on .NET) rather than plain text. The commands are called cmdlets (pronounced "command-lets"), and you'll meet three of the most common ones below: Write-Output prints a value, Get-Date returns the current date/time, and (later) Get-Process lists running programs. Read this worked example, run it, and confirm your output matches.

    Worked example: Write-Output and Get-Date
    # Your very first PowerShell commands.
    # A "cmdlet" (command-let) is a built-in command. Each prints its result.
    
    # Write-Output sends a value down the pipeline (here, a line of text).
    Write-Output "Hello from PowerShell!"
    
    # Get-Date returns a real date/time OBJECT, not just text.
    # -Format turns that object into a string the way you want it.
    Get-Date -Format "dddd, MMMM dd"
    
    # Cmdlets are always named Verb-Noun. "Get" fetches; "Process" is the thing.
    Write-Output "Done."
    Output
    Hello from PowerShell!
    Monday, June 15
    Done.
    This is real code — run it for free atonecompiler.com/powershellor in your own editor.

    Now you try. The script below is almost complete — fill in the two blanks marked ___ using the hints in the # comments, then run it.

    🎯 Your turn: print a greeting and the weekday
    # 🎯 YOUR TURN — replace each ___ then run the script.
    
    # 1) Print a greeting. Write-Output takes text in "double quotes".
    Write-Output ___          # 👉 put your name in quotes, e.g. "Hi, Sam!"
    
    # 2) Print today's weekday name using Get-Date with a format.
    #    The format "dddd" means the full day name (Monday, Tuesday...).
    Get-Date -Format ___      # 👉 replace ___ with "dddd"
    
    # ✅ Expected output (example):
    #    Hi, Sam!
    #    Monday
    Output
    Hi, Sam!
    Monday
    Fill in each ___, then run it for free at onecompiler.com/powershell and check it against the expected output.

    2. The Big Idea: Objects, Not Text

    This is what sets PowerShell apart from bash, CMD, or zsh. In those shells, a command's output is just text, so to use part of it you slice the text by counting spaces with tools like cut or awk — and it breaks the instant a column shifts. PowerShell sends objects down the pipeline (the | symbol, read as "pipe into"). An object carries named properties — a process object has Name, Id, and CPU — so you ask for data by name. Compare the two approaches in the comments below.

    Worked example: sort and select by property name
    # THE BIG IDEA: PowerShell pipes OBJECTS, not text.
    # Get-Process returns process objects. Each one has named properties
    # like Name, Id and CPU — so you can sort and pick columns by name.
    
    # 1) Sort processes by the CPU property, biggest first.
    # 2) Keep only the top 3.
    # 3) Show just the Name, Id and CPU columns as a table.
    Get-Process |
      Sort-Object CPU -Descending |
      Select-Object -First 3 Name, Id, CPU |
      Format-Table -AutoSize
    
    # In bash you'd parse this text with cut/awk by counting spaces.
    # Here you ask for the "CPU" column by NAME — no text-slicing needed.
    Output
    Name       Id   CPU
    ----       --   ---
    chrome    4821  812.45
    pwsh      1990  120.30
    code      3102   98.17
    This is real code — run it for free atonecompiler.com/powershellor in your own editor.

    Your turn again. Memory usage lives in a property called WS (working set). Finish the pipeline by adding the cmdlet that picks which rows and columns to keep.

    🎯 Your turn: top 5 processes by memory
    # 🎯 YOUR TURN — finish the object pipeline.
    # Goal: show the 5 processes using the most memory (the WS property).
    
    # Get-Process gives you objects. Pipe (|) them into the next command.
    Get-Process |
      Sort-Object WS -Descending |
      ___ -First 5 Name, Id, WS    # 👉 the cmdlet that PICKS columns/rows
    
    # ✅ Expected output (a table of 5 rows):
    #    Name      Id    WS
    #    ----      --    --
    #    chrome   4821   612048896
    #    ...
    Output
    Name      Id    WS
    ----      --    --
    chrome   4821   612048896
    code     3102   430112768
    pwsh     1990   198344704
    explorer  900   142671872
    Teams    5567   120033280
    Replace the ___ with the cmdlet that selects rows/columns, then run it at onecompiler.com/powershell. (Your numbers will differ — the shape of the table is what matters.)

    🔎 bash vs PowerShell, side by side

    Goalbash (text)PowerShell (objects)
    Busiest processps aux | sort -rk3 | headGet-Process | Sort-Object CPU -Descending
    Pick one column... | awk '{print $1}'... | Select-Object Name
    Count items... | wc -l(Get-Process).Count

    The bash column relies on the output's exact spacing; the PowerShell column names the data directly, so it keeps working when the display changes.

    3. Verb-Noun Naming & Teaching Yourself

    Every cmdlet is named Verb-Noun: an approved verb plus a singular noun. Get-Process reads processes; Stop-Process ends one; Get-Date reads the date. Learn the common verbs — Get, Set, New, Remove — and you can often guess a command before looking it up. When you can't guess, three cmdlets let PowerShell teach you: Get-Command finds cmdlets by pattern, Get-Help explains one (add -Examples for copy-paste usage), and Get-Member reveals an object's properties so you know what you can sort or select by.

    Worked example: Get-Command, Get-Help, Get-Member
    # When you don't know a cmdlet, ASK PowerShell itself.
    
    # Get-Command finds cmdlets. *Process* matches anything with "Process".
    Get-Command *Process*
    
    # Get-Help explains a cmdlet. -Examples shows ready-to-copy usage.
    Get-Help Get-Date -Examples
    
    # Get-Member lists the properties & methods on whatever an object has.
    # (This is how you discover that Get-Date objects have a .DayOfWeek.)
    Get-Date | Get-Member
    Output
    CommandType  Name           Source
    -----------  ----           ------
    Cmdlet       Get-Process    Microsoft.PowerShell.Management
    Cmdlet       Start-Process  Microsoft.PowerShell.Management
    Cmdlet       Stop-Process   Microsoft.PowerShell.Management
    
    NAME
        Get-Date
    
        -------------------------- Example 1 --------------------------
        Get-Date -Format "yyyy-MM-dd"
    
       TypeName: System.DateTime
    Name        MemberType Definition
    ----        ---------- ----------
    DayOfWeek   Property   System.DayOfWeek DayOfWeek {get;}
    ToString    Method     string ToString()
    This is real code — run it for free atonecompiler.com/powershellor in your own editor.

    Common Errors (and the fix)

    • "...cannot be loaded because running scripts is disabled on this system" — the execution policy is blocking a .ps1 file. Allow your own scripts with Set-ExecutionPolicy -Scope CurrentUser RemoteSigned. (Typing commands straight into the prompt is never blocked.)
    • "The term 'Get-Proces' is not recognized as a name of a cmdlet..." — a typo or a cmdlet that isn't installed. Check the spelling and the Verb-Noun shape, or run Get-Command *Process* to find the real name. Press Tab to autocomplete.
    • Casing looks "wrong" but still runs: PowerShell is case-insensitive, so get-process works. By convention you still write Get-Process in PascalCase — it's far easier to read and is what every example uses.
    • Confusing Write-Host and Write-Output: Write-Output sends an object down the pipeline (so the next command can use it); Write-Host only paints text on screen. Prefer Write-Output unless you specifically want screen-only text.

    📋 Quick Reference

    CmdletAliasWhat it does
    Write-OutputechoSend a value down the pipeline
    Get-DateCurrent date/time object
    Get-Processps / gpsList running processes
    Get-CommandgcmFind cmdlets by pattern
    Get-HelphelpShow a cmdlet's documentation
    Sort-ObjectsortSort objects by a property
    Select-ObjectselectPick properties / first N rows

    Frequently Asked Questions

    Q: Is PowerShell only for Windows?

    No. Windows PowerShell 5.1 ships with Windows, but the modern PowerShell 7+ (the 'pwsh' command) is cross-platform and runs on Windows, macOS and Linux. The cmdlets and the object pipeline work the same way on all of them.

    Q: What is the difference between PowerShell and bash?

    Bash passes plain text between commands, so you slice that text with tools like grep, cut and awk. PowerShell passes structured .NET objects, so instead of parsing text you ask for a property by name (for example Sort-Object CPU). That makes PowerShell more reliable for automation because there is no fragile text-parsing step.

    Q: Why are commands named with a dash, like Get-Process?

    Every cmdlet follows a Verb-Noun convention: an approved verb (Get, Set, New, Remove) plus a singular noun. Once you learn the verbs, you can guess command names — if Get-Process reads processes, Stop-Process ends one. It makes thousands of cmdlets predictable.

    Q: I get an error that scripts are disabled — how do I fix it?

    Windows blocks .ps1 scripts by default for safety. Run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned to allow your own scripts to run while still requiring downloaded ones to be signed. Typing commands directly into the prompt is never blocked by this policy.

    Mini-Challenge: Top CPU Report

    No blanks this time — just a brief and an outline. Build the pipeline yourself from the cmdlets you met in this lesson, run it, and compare the shape of your table to the expected result in the comments.

    🎯 Mini-Challenge: build the pipeline
    # 🎯 MINI-CHALLENGE: "Top CPU report"
    # Using ONLY cmdlets from this lesson, build a one-line pipeline that:
    #   1. Gets all running processes          (Get-Process)
    #   2. Sorts them by the CPU property, highest first
    #   3. Keeps just the top 5
    #   4. Shows the Name, Id and CPU columns as a tidy table
    #
    # Hints (cmdlets you've met): Get-Process, Sort-Object,
    #                             Select-Object, Format-Table
    #
    # ✅ Expected: a 5-row table with columns Name, Id, CPU.
    
    # your pipeline here
    Write your pipeline, then run it at onecompiler.com/powershell or in your own PowerShell terminal.

    🎉 Lesson Complete!

    • ✅ PowerShell is an object-oriented, cross-platform shell (Windows, macOS, Linux)
    • ✅ The pipeline (|) passes objects with named properties — not plain text like bash
    • ✅ Cmdlets are named Verb-Noun (Get-Process, Stop-Process) so they're predictable
    • Write-Output, Get-Date, and Get-Process are your first everyday cmdlets
    • Get-Command, Get-Help, and Get-Member let PowerShell teach you the rest
    • Next lesson: Cmdlets and Syntax — parameters, aliases, and building longer pipelines

    Sign up for free to track which lessons you've completed and get learning reminders.

    Cookie & Privacy Settings

    We use cookies to improve your experience, analyze traffic, and show personalized ads. You can manage your preferences below.

    By clicking "Accept All", you consent to our use of cookies for analytics and personalized advertising. You can customize your preferences or reject non-essential cookies.

    Privacy PolicyTerms of Service

    Install LearnCodingFast

    Learn faster with the app on your home screen.