Array and Array Operations in Windows PowerShell

10/20/2009

Array Operations

Does this array have a 3 in it

1,2,3,5,3,2 –contains 3

Return all elements equal to 3:

1,2,3,5,3,2 –eq 3

Return all elements less than 3:

1,2,3,5,3,2 –lt 3

Test if 2 exists in collection:

if (1, 3, 5 –contains 2) …

Other operators: -gt, -le, -ge, -ne

Arrays

“a”,“b”,”c”

array of strings

1,2,3

array of integers

@()

empty array

@(2)

array of 1 element

1,(2,3),4

array within array

,”hi”

Array of one element

$a[5]

sixth element of array*

$a[2][3]

fourth element or the third

 

element of an array

$a[2..20]

Return elements 3 thru 21

· Arrays are zero based.

Posted in: MS Windows Software Programming| Tags: Windows PowerShell Windows PowerShell Array Array Operations

Hot Posts

Latest posts

Tags

Others

Sponsors