0
0
PowerShellscripting~10 mins

Why variables store data in PowerShell - See It in Action

Choose your learning style9 modes available
Why variables store data
📖 Scenario: You are learning how to use variables in PowerShell to store information. Variables help you keep data so you can use it later in your script, just like putting things in labeled boxes to find them easily.
🎯 Goal: Build a simple PowerShell script that creates a variable to store a name, then stores an age in another variable, and finally prints both values to the screen.
📋 What You'll Learn
Create a variable called $name and assign it the value "Alice"
Create a variable called $age and assign it the value 30
Print the values of $name and $age using Write-Output
💡 Why This Matters
🌍 Real World
Variables let you save user input, settings, or results in scripts to automate tasks.
💼 Career
Knowing how to store and use data in variables is a basic skill for any scripting or automation job.
Progress0 / 4 steps
1
Create a variable to store a name
Create a variable called $name and assign it the text value "Alice".
PowerShell
Need a hint?

Use = to assign the value "Alice" to the variable $name.

2
Create a variable to store an age
Create a variable called $age and assign it the number 30.
PowerShell
Need a hint?

Remember, numbers do not need quotes in PowerShell.

3
Print the stored name and age
Use Write-Output to print the values of $name and $age on separate lines.
PowerShell
Need a hint?

Use Write-Output followed by the variable name to display its value.

4
Run the script to see the output
Run the script to display the stored name and age. The output should show Alice on the first line and 30 on the second line.
PowerShell
Need a hint?

Run the script by pressing Enter or using your PowerShell environment's run command.