The simple response is you are adding an Array to another Array to make a longer Array and then passing that as a parameter to Select-Object, but let’s walk through that to validate what is happening.
If we look at the following
PS C:\> $selectkeys = "Position0", "Position1", "Position2"
PS C:\> $selectkeys
Position0
Position1
Position2
PS C:> $selectkeys.GetType()
IsPublic IsSerial Name BaseType
True True Object System.Array
We see that PowerShell is interpreting the command as setting an array of strings to the variable $selectkeys. This is the same as typing it as an array literal
PS C:\> $selectkeys = @("Position0", "Position1", "Position2")
PS C:\> $selectkeys
Position0
Position1
Position2
PS C:> $selectkeys.GetType()
IsPublic IsSerial Name BaseType
True True Object System.Array
If we look at each position in the array we see our individual values, and see that position 3 has no value
PS C:\> $selectkeys[0]
Position0
PS C:\> $selectkeys[1]
Position1
PS C:\> $selectkeys[2]
Position2
PS C:\> $selectkeys[3]
PS C:\>
If we create another array like we did in the beginning, we can add that to our existing array that is stored in the $selectkeys variable to make a longer array. Note: where the new entries are added is determined by which side of the “+” sign they are placed on.
PS C:\> "Position3", "Position4" + $selectkeys
Position3
Position4
Position0
Position1
Position2
PS C:\>
PS C:> $selectkeys + “Position3”, “Position4”
Position0
Position1
Position2
Position3
Position4
Where this can get you in trouble is if you are only adding one additional string to the array
PS C:\> "Position3" + $selectkeys
Position3Position0 Position1 Position2
PS C:> (“Position3” + $selectkeys).GetType()
IsPublic IsSerial Name BaseType
True True String System.Object
As you can see the result is now a string rather than your previous array. This is because PowerShell will interpret a single string in quotes as a string object rather than an array of string objects. In order to add a single string to the array, we have to help PowerShell by telling it this is an array using an array literal. PowerShell can then properly add the new array values with the existing array. Technically, the way the statement is structured, @(“Position3”) is the array it starts with and adds all of the values from the array stored in $selectkeys to it. The result is that even though the string says “Position3” it is actually in Position 0 in the array.
PS C:\> @("Position3") + $selectkeys
Position3
Position0
Position1
Position2
PS C:> (@(“Position3”) + $selectkeys).GetType()
IsPublic IsSerial Name BaseType
True True Object System.Array
So now you see what is happening with @(“ProcessName”) + $selectkeys
, but there is still the additional () around it. Those parenthesis simple tell powershell to process the @(“ProcessName”) + $selectkeys
code first and then return the results of that processing as a single parameter to Select-Object. Otherwise, Select-Object would see a spaces between the “+” the arrays and think it is looking at 3 parameters rather than one.
Select-Object (@("ProcessName") + $selectkeys)
Hope that helps.