A PowerShell array holds a list of data items. The data elements of a PowerShell array need not be of the same type, unless the data type is declared (strongly typed). Arrays are built using operators or casts. The way to build an array in PowerShell is to use the comma operator.
A variable parameter is use when you need to store a static value or the results of some other calculation/collection/operation. One can pass an array data as a parameter or even a named parameter. For Example:
Function Show-Friends
{
[CmdletBinding()]
Param
(
[string] $MainPerson,
[string[]] $Friends
)
"Main person is ",$MainPerson
'Friends count is : ' ,$Friends.Count
foreach($Friend in $Friends)
{
$MainPerson + " has a Friend named: ” ,$Friend
}
}
Show-Friends
Show-Friends -MainPerson:Smith -Friends:@('Jon', 'Joshua')
Show-Friends Smith ('Jon', 'Joshua')
However, your second block is not a ‘variable parameter’ as noted by you, it’s a hastable. Hash Tables (also known as Associative arrays or Dictionaries) are a type of array that allows the storage of paired Keys and Values, rather like a simple database table. Unlike normal arrays where you refer to each element via a numeric index, the keys of a hash table can be strings. The Key values do still need to be unique, if you try to add the same key twice PowerShell will return an error (“item has already been added”).
For a review regarding variable and parameters, then look here:
About Functions Advanced Parameters
‘docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-5.1’
Simplify Your PowerShell Script with Parameter Validation
‘Simplify Your PowerShell Script with Parameter Validation - Scripting Blog’
PowerShell – Passing Parameters as Variables using Remote Management and Invoke-Command
‘blogs.technet.microsoft.com/ralphkyttle/2015/06/04/powershell-passing-parameters-as-variables-using-remote-management-and-invoke-command’
Use the Get-Command PowerShell Cmdlet to Find Parameter Set Information
‘Use the Get-Command PowerShell Cmdlet to Find Parameter Set Information - Scripting Blog’
Use Parameter Sets to Simplify PowerShell Commands
‘Use Parameter Sets to Simplify PowerShell Commands - Scripting Blog’
Weekend Scripter: Use PowerShell to Find Dynamic Parameters
‘Weekend Scripter: Use PowerShell to Find Dynamic Parameters - Scripting Blog’
Dynamic ValidateSet in a Dynamic Parameter
'docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-5.1
However, your post title is ‘Add to array’
Here is a good write up on add / remove reltive to arrays
‘Adding and Removing Items from a PowerShell Array – Jonathan Medd's Blog’