Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does @() mean in Powershell?

Tags:

powershell

I've seen this a few times in Powershell, and was curious what it meant :

@() 

For example, in this block :

    [datetime]$StartDate = ([datetime]::now.ToShortDateString())     $TodaysMail = @() 

thanks !

like image 553
Caffeinated Avatar asked Feb 25 '15 23:02

Caffeinated


People also ask

What is mean by $_ in PowerShell?

$_ is an alias for automatic variable $PSItem (introduced in PowerShell V3. 0; Usage information found here) which represents the current item from the pipe.

What does $() mean in PowerShell?

The $() is the subexpression operator. It causes the contained expressions to be evaluated and it returns all expressions as an array (if there is more than one) or as a scalar (single value).

What does $Script mean in PowerShell?

$PSScriptRoot - Contains the directory from which a script is being run. In PowerShell 2.0, this variable is valid only in script modules ( .

What is @{} in PowerShell?

@{} in PowerShell defines a hashtable, a data structure for mapping unique keys to values (in other languages this data structure is called "dictionary" or "associative array"). @{} on its own defines an empty hashtable, that can then be filled with values, e.g. like this: $h = @{} $h['a'] = 'foo' $h['b'] = 'bar'


1 Answers

The @ indicates an array. @() simply creates an empty array. I.e. this snippet:

$TodaysMail = @() 

Would yield a variable TodaysMail representing an empty array.

like image 109
Alexander Sjöholm Avatar answered Sep 23 '22 02:09

Alexander Sjöholm