Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Working with Variables | Getting Started with PowerShell
PowerShell Basics

bookWorking with Variables

Sveip for å vise menyen

1234
# Defining and assigning values to variables in PowerShell $greeting = "Hello, PowerShell!" $number = 42 $isEnabled = $true
copy

Variables in PowerShell allow you to store and reuse data throughout your scripts. When naming variables, follow these rules:

  • Start the name with a dollar sign ($);
  • The first character after $ must be a letter or underscore;
  • Use only letters, numbers, and underscores in the name;
  • Avoid spaces and special characters;
  • Variable names are not case-sensitive. Variable scope determines where a variable can be accessed. Most variables you create are local to your script or session, but you can specify other scopes like global: or script: if required.
1234
# Variable interpolation in PowerShell strings $name = "Sam" $message = "Welcome, $name!" Write-Output $message # Output: Welcome, Sam!
copy

1. Which of the following is a valid variable name in PowerShell?

2. What is variable interpolation in PowerShell strings?

question mark

Which of the following is a valid variable name in PowerShell?

Select the correct answer

question mark

What is variable interpolation in PowerShell strings?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 3

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Seksjon 1. Kapittel 3
some-alt