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 !
$_ is an alias for automatic variable $PSItem (introduced in PowerShell V3. 0; Usage information found here) which represents the current item from the pipe.
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).
$PSScriptRoot - Contains the directory from which a script is being run. In PowerShell 2.0, this variable is valid only in script modules ( .
@{} 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'
The @
indicates an array. @()
simply creates an empty array. I.e. this snippet:
$TodaysMail = @()
Would yield a variable TodaysMail
representing an empty array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With