Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Core Tech
Google Cloud Platform icon
Labs

Create an Advanced PowerShell Function for System Optimization

In this lab, you'll practice building a professional-grade PowerShell function. You'll have a reusable and well-documented PowerShell function when you're finished.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Beginner
Last updated
Jul 30, 2025
Duration
1h 45m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Getting Started in the Lab Environment

    Here are the initial instructions and explanation of the lab environment. Read this while your environment is busy creating itself from nothing. Yes, this violates physics; we know. How fun!

  2. Challenge

    Create a Function Skeleton with CmdletBinding

    You will begin by constructing the foundational elements of a PowerShell function aimed at a fictional scenario around system optimization. Named Optimize-LocalSystem, this function will begin as a basic structure. You'll particularly focus on the CmdletBinding attribute, a key element that enables advanced features like WhatIf and Confirm. By the end of this short challenge, you'll have a skeletal framework for your Optimize-LocalSystem function, and an understanding of why CmdletBinding is crucial for advanced functionalities in PowerShell functions.

  3. Challenge

    Add the First Parameter

    You'll continue to build upon the Optimize-LocalSystem function. Your objective is to make the function more versatile by adding the ability to perform different operations: either checking for system updates or cleaning temporary files.

  4. Challenge

    Add WhatIf and Confirm Support

    In this challenge, you'll focus on adding support for WhatIf and Confirm, specifically for the CleanTempFiles operation. This is important because deleting files is a sensitive task that could benefit from additional user confirmation, or even a "dry run" to simulate the outcome.

  5. Challenge

    Implement Parameter Validation

    Dive into parameter validation in PowerShell functions for reliability. You will begin with the [ValidateSet] attribute to limit inputs, make crucial parameters mandatory, and explore dynamic parameters appearing under specific conditions. By the end, you'll enhance function resilience and effectiveness.

  6. Challenge

    Add Error Handling

    When your script fails silently due to non-terminating errors, it threatens reliability. This challenge teaches you to detect and address these errors, enhancing script robustness and trust.

  7. Challenge

    Implement Parameter Sets

    Enhance your PowerShell function to run operations when given input manually, and when given a CSV file as input, with one command. This challenge makes your function more versatile and efficient.

  8. Challenge

    Add Pipeline Support

    The challenge refines Optimize-LocalSystem to support pipeline input. It emphasizes the begin, process, and end blocks for efficient pipeline handling. Furthermore, the Operation parameter accepts pipeline input by name, optimizing batch operations in PowerShell.

  9. Challenge

    Write Help Content

    Your Optimize-LocalSystem function is pretty robust, but could it be "user-friendlier"? That's where comment-based help comes in. By the end of this challenge, users will be able to type Get-Help Optimize-LocalSystem and get all the details they need to use your function like a pro.

  10. Challenge

    Manage Output

    In the IT realm, predictability is a virtue. Imagine scripting functions that don't just end at producing results, but those results are intuitive, structured, and empower further actions. You will use the OutputType attribute, which will ensure your function only returns what’s necessary.

About the author

Adam Bertram is an independent consultant, technical writer, trainer, and presenter. Adam specializes in consulting and evangelizing all things IT automation, mainly focused around Windows PowerShell.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight