Assignment stores a value in a variable. In PowerShell, write the variable name, an equals sign, and the value you want to keep. The dollar sign signals that what follows is a variable name; it is not part of the name itself. section 16.2
Store and reuse a computer name
Try this with your test server’s name: $var = "SRV-02". Entering $var afterward displays SRV-02. The same pattern lets you reuse values in commands, such as assigning a process ID and running Get-Process -Id $var. section 16.2
Keep these practical details in mind:
- Use sensible variable names containing letters, numbers, and underscores; names can be long, while names with spaces require curly braces. section 16.2
- Variables disappear when the shell session closes. section 16.2
- Prefer normal assignment syntax over variable-management cmdlets when writing scripts, because PowerShell can better predict the value’s data style. section 16.7
$var = "SRV-02"
See the minimal assignment command: $var = "SRV-02". section 16.2






