Default parameter values
📖 Scenario: You are creating a simple PowerShell script to greet users. Sometimes users provide their name, and sometimes they don't. You want the script to say "Hello, Guest!" when no name is given.
🎯 Goal: Build a PowerShell function that uses a default parameter value to greet a user by name or greet "Guest" if no name is provided.
📋 What You'll Learn
Create a function named
Greet-User with a parameter Name that has a default value of 'Guest'.Inside the function, output the greeting:
Hello, <Name>! using the parameter value.Call the function twice: once without any argument and once with the argument
'Alice'.Print the output of both calls.
💡 Why This Matters
🌍 Real World
Scripts often need to handle missing information gracefully. Using default parameter values lets scripts run smoothly without requiring all inputs every time.
💼 Career
Knowing how to use default parameters is essential for writing flexible automation scripts, which is a common task in IT, DevOps, and system administration roles.
Progress0 / 4 steps