Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting VBScript's ReDim Statement

Windows PowerShell

Definition: Declares dynamic-array variables, and allocates or reallocates storage space at procedure level.


In general there’s no need for a ReDim statement in Windows PowerShell; arrays can be resized without having to explicitly call ReDim (and without having to explicitly preserve the existing contents of the array). For example, suppose the following 5 items are assigned to the array $a:

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

Want to add a new value - 100 - to the array? This is all you have to do:

$a = $a + 100

If you echo back the value of $a you’ll get the following:


Likewise you can truncate an array without explicitly redimensioning anything. Suppose you want only the first three values in $a. This code assigns just those first three values (using the syntax 0..2, which means start with item 0 in the array, end with item 2, and take all the values in between) and assigns them to $a:

$a = $a[0..2]

What do you get back when you execute this command? This is what you get back:


Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft