Using Parameters in PowerShell Scripts
📖 Scenario: You are creating a PowerShell script to greet users by their name and optionally their age. This script will use parameters to accept input values when run.
🎯 Goal: Build a PowerShell script that uses parameters to accept a Name and an optional Age. The script will greet the user by name and mention their age if provided.
📋 What You'll Learn
Create a parameter block with a mandatory
Name parameter of type stringAdd an optional
Age parameter of type int with a default valueUse the parameters inside the script to print a greeting message
Print the greeting message showing the name and age if provided
💡 Why This Matters
🌍 Real World
Scripts with parameters let users provide input values when running them, making scripts flexible and reusable for different situations.
💼 Career
Knowing how to use parameters is essential for automation tasks, system administration, and writing professional PowerShell scripts that others can use easily.
Progress0 / 4 steps