Monday, December 19, 2022

[FIXED] What does the "@" symbol do in PowerShell?

Issue

I've seen the @ symbol used in PowerShell to initialise arrays.

What exactly does the @ symbol denote and where can I read more about it?


Solution

PowerShell will actually treat any comma-separated list as an array:

"server1","server2"

So the @ is optional in those cases. However, for associative arrays, the @ is required:

@{"Key"="Value";"Key2"="Value2"}

Officially, @ is the "array operator." You can read more about it in the documentation that installed along with PowerShell, or in a book like "Windows PowerShell: TFM," which I co-authored.



Answered By - Don Jones
Answer Checked By - Clifford M. (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.