PowerTip: Add Two PowerShell Arrays Together

PowerTip: Add Two PowerShell Arrays Together

  • Comments 1
  • Likes

Summary: Easily add two Windows PowerShell arrays together.

Hey, Scripting Guy! Question If I have an array stored in one variable, and another array stored in another variable, how can I add them together?

Hey, Scripting Guy! Answer Use the + operator to add to arrays together:

PS C:\> $a = 2,3,4

PS C:\> $b = 5,6,7

PS C:\> $c = $a + $b

PS C:\> $c







PS C:\>

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Missing from this is the related question of how to do this with distinct results, similar to the SQL "Select Distinct" command. i.e, if both of the above lists contained "1", how do i return a list that contains "1" only once.