PowerTip: Change Value of Element in Array with PowerShell


Summary: Learn how to use Windows PowerShell to change the value of an element in an array.

Hey, Scripting Guy! Question How can I use Windows PowerShell to update one of the values in one of the elements of an array?

Hey, Scripting Guy! Answer Use the Item method to retrieve the element and assign a new value. Here is an example of
           updating the value of the first element in an array:

$a = 1,2,3,4,5

$a.Item(0) = 12


Note  Remember that in Windows PowerShell, all arrays are zero-based. This means that the first
element is actually element 0.