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

Working with Variables

Scorri per mostrare il menu

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

# Variable interpolation in PowerShell strings
$name = "Sam"
$message = "Welcome, $name!"
Write-Output $message  # Output: Welcome, Sam!
  • 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.
question mark

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

Seleziona la risposta corretta

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 3

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Sezione 1. Capitolo 3
some-alt