Friday, August 8, 2014

#21 : Creating an Array in Powershell

I have gone through several article to understand this, but below is the one which looks most simple to me, the reason is - below one is dynamic and can be used easily in your scripts -

$arr=@()
$arr += "ABC"
$arr += "XYZ"
$arr += "PQR"


$arr[0]
ABC
$arr[1]
XYZ
$arr[2]
PQR

$arr.count
3

for ($x=0; $x -lt $arr.count; $x++) { echo ${arr}[$x] }
ABC
XYZ
PQR
Simple and effective! This is something which we want in all our scripts.
This is dynamic and you can assign so many values in different functions. I will take in detail later.... Keep sending your comments / mails.



No comments:

Post a Comment

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...