Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Converting VBScript's ReDim Statement


Windows PowerShell


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

ReDim

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:


1
2
3
4
5
100

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:


1
2
3


Return to the VBScript to Windows PowerShell home page

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.