PowerShell fundamentals: cmdlets, pipeline, scripting
Learn from scratch to use PowerShell on Windows and Linux for object-based commands, data filtering and small automation scripts.
Level 101 · 24 lessons · 27 practice labs
Lessons
First steps
- What PowerShell is and how it differs from a classic shell: You can explain that PowerShell commands return objects instead of text and why administrators and security teams use it.
- The cmdlet pattern: Verb-Noun, Get-Help and Get-Command: Using the Verb-Noun pattern, you can find the right command with Get-Command and Get-Help without memorizing.
- Navigating the file system: Get-ChildItem and Set-Location: With Get-ChildItem and Set-Location you can move between directories and list files by name, type and size.
- Managing files and folders: New-Item, Copy-Item, Move-Item, Remove-Item: You can set up a project workspace by command, copy and move files, and preview deletions first with -WhatIf.
- Reading and writing text files: Get-Content, Set-Content, Add-Content: With Get-Content, Set-Content and Add-Content you can read and update a text file and redirect output to a file.
- Variables, strings and arithmetic: You can define variables, join and format strings, and do simple calculations.
- Short task: move old log files into an archive folder
Objects, the pipeline and data
- Objects and properties: Get-Member: With Get-Member you can discover the properties and methods of the object a command returns.
- The pipeline: Where-Object, Select-Object and Sort-Object: With Where-Object, Select-Object and Sort-Object you can filter and sort a list to find files that need attention.
- Grouping and measuring: Group-Object and Measure-Object: With Group-Object and Measure-Object you can summarize the total, average and distribution of a collection of files or records.
- Arrays, hashtables and custom objects: With arrays, hashtables and PSCustomObject you can build structured data such as a device inventory in memory.
- Formatting output: Format-Table, Format-List and Out-File: You can format output as a table or list, write it to a file, and tell the on-screen view apart from the underlying data.
- CSV data: Import-Csv and Export-Csv: With Import-Csv and Export-Csv you can read a stock or inventory table and pick out low-stock records.
- JSON data: ConvertFrom-Json and ConvertTo-Json: With ConvertFrom-Json and ConvertTo-Json you can read an application configuration and safely update one value.
- Searching and transforming text: Select-String, -match and -replace: With Select-String and regular expressions you can pull error lines out of application logs and reshape them.
- Short task: build a department summary from a CSV staff list
Scripts and automation
- Your first script and execution policy: .ps1 and ExecutionPolicy: You can write and run your first .ps1 script and explain what ExecutionPolicy does and does not protect.
- Conditions and loops: if, foreach and switch: With if, foreach and switch you can write a small script that sorts incoming documents by type.
- Functions and script parameters: With a param block and functions you can write a reusable inventory report script.
- Error handling and input validation: try/catch, -ErrorAction: With try/catch, -ErrorAction and parameter validation you can make a data import script reliable against errors.
- Managing processes and services: Get-Process, Stop-Process, Get-Service: With Get-Process and Get-Service you can find and stop a stalled process and report on service states.
- Reading event logs: Get-WinEvent: With Get-WinEvent you can filter security events such as failed sign-ins and build a timeline.
- Calling REST APIs: Invoke-RestMethod: With Invoke-RestMethod you can fetch data from an API and update a record, using a token without hardcoding it in the script.
- Capstone: a schedulable inventory automation: You can combine file, CSV and JSON steps in one script to build a project inventory automation that can run daily.
Practice labs
- Explore an object's properties with Get-Member: Inspect process objects with Get-Member and submit the name of the property holding memory use.
- Group and measure files by extension: Group the files in the shared folder by extension and report each group's file count and total size.
- Build a combined report with custom objects: Create a custom object carrying host name, free space and busiest process from disk and process data and write it to a file.
- Build a department summary from a staff CSV: Import the staff CSV, count people per department and export the result to a new CSV.
- Update a value in a JSON config: Convert a JSON config to an object, change the log level and write it back preserving depth.
- Join two CSV files on a shared column: Join the device and user CSVs on user ID and report unmatched devices in a separate file.
- Write and run a first .ps1 script: Create a script that prints the host name, date and free disk space and run it with pwsh.
- Sort files into folders by type: Write a script using foreach and switch to move downloaded files into document, image and archive folders by extension.
- Write a script that reports errors without stopping: Write a script that copies listed files and catches missing or unreadable ones with try/catch into an error report.
- Find the right cmdlet with Get-Command: Find a cmdlet for a job you cannot name using Get-Command and Get-Help, run its example and save the output.
- Find the right parameter in the help page: Use Get-Help -Parameter and -Examples to find the Get-ChildItem parameters that list only files and include hidden items, run the command and write down the parameter names you used.
- Prove from the help which cmdlet takes pipeline input: List the cmdlets that work with services using Get-Command -Noun and -ParameterName, resolve their short names with Get-Alias, read the about_ help topic to find the parameter that accepts pipeline input and confirm it with an example.
- Move old log files into an archive folder: Move .log files older than thirty days to an archive folder with Get-ChildItem and Move-Item.
- Find the ten largest files in a tree: Scan the project tree recursively and print the ten largest files with their sizes as a table.
- Change a value across config files: Use Get-Content and Set-Content to replace the old host name in every .conf file, backing each up first and listing the changed files.
- Find the lines containing a word in a log: Use Select-String to find the lines containing ERROR in the application log and write how many there are, with the line number of the first match.
- Extract IPs of failed logins from a log: Use Select-String and -match to extract IP addresses from failed-login lines and give counts per IP.
- Scan many logs for an error with its context: Use Select-String with -Path, -Context and named capture groups to pull timeout errors with the two lines before them from every log in a folder, then count them by file and service name in a table.
- List the processes using the most memory: Sort processes by memory use and show the top five with name, ID and memory in megabytes.
- Find and stop a runaway process: Find the process using the most CPU with Get-Process, record its name and start time, end it with Stop-Process and confirm it has not come back.
- Report service and process health as objects: Write a function that combines running state, memory and start time for given process names into one object and export the output to CSV.
- Add a parameter with a default to a script: Add a -Path parameter with a param block to a script that hard-codes its folder; default to the current folder when it is omitted, run it both ways and save the output.
- Write a function that takes parameters: Write a function taking a folder path and a number of days that lists files older than that.
- Write a clean-up script that validates input: Write a script that refuses missing or dangerous paths such as the root directory and deletes old files in a valid path.
- Write basic system facts to a JSON file: Gather the host name, operating system version and free disk space into one object and save it to a file with ConvertTo-Json.
- Fetch and filter data from a local API: Call the lab's local API with Invoke-RestMethod and print the records whose status is not active as a table.
- Write a schedulable inventory script: Prepare a non-interactive script that collects OS, disk and running process data and writes it to a dated JSON file.
About this course
Learn from scratch to use PowerShell on Windows and Linux for object-based commands, data filtering and small automation scripts.
What you will learn
- First steps
- Objects, the pipeline and data
- Scripts and automation
Prerequisites
No prior knowledge is needed; the course starts from zero.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at beginner level; every term is explained where it first appears.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.