PowerTip: Use PowerShell to Copy Array

PowerTip: Use PowerShell to Copy Array

  • Comments 1
  • Likes

Summary: Use Windows PowerShell to copy an array.

Hey, Scripting Guy! Question How can I use Windows PowerShell to copy the contents of one array over another array?

Hey, Scripting Guy! Answer One way to do this is to use the Copy static method from the System.Array .NET Framework class, for example:

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

PS C:\> $b = 6,7,8,9,10

PS C:\> [array]::copy($a,$b,5)

PS C:\> $b






Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Could be useful but this is more useful. First expand $a then copy - instant catenation.

    static void Copy(array sourceArray, long sourceIndex, array destinationArray, long destinationIndex, long length)