I've looked on the web in various places, but I am unable to figure out to
create and manipulate multi-dimensional arrays in Powershell. Could some one
post an explination and example please?
Thanks.
I've looked on the web in various places, but I am unable to figure out to
create and manipulate multi-dimensional arrays in Powershell. Could some one
post an explination and example please?
Thanks.
Tim Munro wrote:From Lee Holmes' just-released Windows PowerShell Cookbook (*everyone*
> I've looked on the web in various places, but I am unable to figure out to
> create and manipulate multi-dimensional arrays in Powershell. Could some one
> post an explination and example please?
>
> Thanks.
>
>
should buy it!):
PSH> $multi=@(PSH> $multi[0][1]
>> (1,2,3,4),
>> (5,6,7,8)
>> )
>>
2
PSH> $multi[1][3]
8
That's one way, another requires you call a class from the .NET framework.
Lee's book explains this in greater details.
Marco
--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp
PowerGadgets MVP
http://www.powergadgets.com/mvp
Blog:
http://marcoshaw.blogspot.com
I would be more interested why you would feel the need for them. Being able
to create Custom Objects, Arrays, and Hash tables I dont see the need for
multi-dimensional arrays.
I am not saying there isnt any, but so far everyone that has asked how to
use hasn't needed them.
Hello Marco Shaw [MVP],
PSH>> $multi=@(
> Tim Munro wrote:
>> From Lee Holmes' just-released Windows PowerShell Cookbook
>> I've looked on the web in various places, but I am unable to figure
>> out to create and manipulate multi-dimensional arrays in Powershell.
>> Could some one post an explination and example please?
>>
>> Thanks.
>>
> (*everyone* should buy it!):
>
PSH>>PSH>> $multi[0][1]
>>> (1,2,3,4),
>>> (5,6,7,8)
>>> )
PSH>>PSH>> $multi[1][3]
> 2
>
PSH>>
> 8
>
> That's one way, another requires you call a class from the .NET
> framework.
>
> Lee's book explains this in greater details.
>
> Marco
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
> Blog:
> http://marcoshaw.blogspot.com
Thank you gentlemen. Why I want them? I'm pulling email information from AD,
to compare it to a "Global Alias" table kept on another system. For each
mail-enabled object, I need to hold two distinct pieces of information. I
thought a simple 2D associative array would be the easiest to play with. If
there's a better way to do this, I'm all ears (eyes?). (I'm still quite new
to PS but want to learn).
"Brandon Shell [MVP]" <tshell.Mask@xxxxxx> wrote in message
news:68d19cd17078c9f65773edb050@xxxxxx
>I would be more interested why you would feel the need for them. Being able
>to create Custom Objects, Arrays, and Hash tables I dont see the need for
>multi-dimensional arrays.
>
> I am not saying there isnt any, but so far everyone that has asked how to
> use hasn't needed them.
>
> Hello Marco Shaw [MVP],
>> PSH>> $multi=@(
>> Tim Munro wrote:
>>>> From Lee Holmes' just-released Windows PowerShell Cookbook
>>> I've looked on the web in various places, but I am unable to figure
>>> out to create and manipulate multi-dimensional arrays in Powershell.
>>> Could some one post an explination and example please?
>>>
>>> Thanks.
>>>
>> (*everyone* should buy it!):
>>
> PSH>>> PSH>> $multi[0][1]
>>>> (1,2,3,4),
>>>> (5,6,7,8)
>>>> )
> PSH>>> PSH>> $multi[1][3]
>> 2
>>
> PSH>>>
>> 8
>>
>> That's one way, another requires you call a class from the .NET
>> framework.
>>
>> Lee's book explains this in greater details.
>>
>> Marco
>>
>> PowerGadgets MVP
>> http://www.powergadgets.com/mvp
>> Blog:
>> http://marcoshaw.blogspot.com
>
What Exchange version?
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
> Thank you gentlemen. Why I want them? I'm pulling email information
> from AD, to compare it to a "Global Alias" table kept on another
> system. For each mail-enabled object, I need to hold two distinct
> pieces of information. I thought a simple 2D associative array would
> be the easiest to play with. If there's a better way to do this, I'm
> all ears (eyes?). (I'm still quite new to PS but want to learn).
>
> "Brandon Shell [MVP]" <tshell.Mask@xxxxxx> wrote in message
> news:68d19cd17078c9f65773edb050@xxxxxx
>
>> I would be more interested why you would feel the need for them.
>> Being able to create Custom Objects, Arrays, and Hash tables I dont
>> see the need for multi-dimensional arrays.
>>
>> I am not saying there isnt any, but so far everyone that has asked
>> how to use hasn't needed them.
>>
>> Hello Marco Shaw [MVP],
>>>> PSH>> $multi=@(
>>> Tim Munro wrote:
>>>
>>>> I've looked on the web in various places, but I am unable to figure
>>>> out to create and manipulate multi-dimensional arrays in
>>>> Powershell. Could some one post an explination and example please?
>>>>
>>>> Thanks.
>>>>
>>> From Lee Holmes' just-released Windows PowerShell Cookbook
>>> (*everyone* should buy it!):
>>>
>> PSH>>>> PSH>> $multi[0][1]
>>>>> (1,2,3,4),
>>>>> (5,6,7,8)
>>>>> )
>> PSH>>>> PSH>> $multi[1][3]
>>> 2
>>>
>> PSH>>
>>> 8
>>>
>>> That's one way, another requires you call a class from the .NET
>>> framework.
>>>
>>> Lee's book explains this in greater details.
>>>
>>> Marco
>>>
>>> PowerGadgets MVP
>>> http://www.powergadgets.com/mvp
>>> Blog:
>>> http://marcoshaw.blogspot.com
A hash table would be perfect.
$mEnabled = @{} # creates a Hash table
$mEnabled.Add($objName,$value1) # adds the mail enabled key
$mEnabled.$ObjName += $value2 # adds second value to key
You will get back a Hash table with the key as the Mail Enabled obj, and the
value is an array with the values.
"Tim Munro" <Excelsior@xxxxxx> wrote in message
news:etBPf9qKIHA.4272@xxxxxx
> Thank you gentlemen. Why I want them? I'm pulling email information from
> AD, to compare it to a "Global Alias" table kept on another system. For
> each mail-enabled object, I need to hold two distinct pieces of
> information. I thought a simple 2D associative array would be the easiest
> to play with. If there's a better way to do this, I'm all ears (eyes?).
> (I'm still quite new to PS but want to learn).
>
>
> "Brandon Shell [MVP]" <tshell.Mask@xxxxxx> wrote in message
> news:68d19cd17078c9f65773edb050@xxxxxx>
>>I would be more interested why you would feel the need for them. Being
>>able to create Custom Objects, Arrays, and Hash tables I dont see the need
>>for multi-dimensional arrays.
>>
>> I am not saying there isnt any, but so far everyone that has asked how to
>> use hasn't needed them.
>>
>> Hello Marco Shaw [MVP],
>>>> PSH>> $multi=@(
>>> Tim Munro wrote:
>>>
>>>> I've looked on the web in various places, but I am unable to figure
>>>> out to create and manipulate multi-dimensional arrays in Powershell.
>>>> Could some one post an explination and example please?
>>>>
>>>> Thanks.
>>>>
>>> From Lee Holmes' just-released Windows PowerShell Cookbook
>>> (*everyone* should buy it!):
>>>
>> PSH>>>> PSH>> $multi[0][1]
>>>>> (1,2,3,4),
>>>>> (5,6,7,8)
>>>>> )
>> PSH>>>> PSH>> $multi[1][3]
>>> 2
>>>
>> PSH>>>>
>>> 8
>>>
>>> That's one way, another requires you call a class from the .NET
>>> framework.
>>>
>>> Lee's book explains this in greater details.
>>>
>>> Marco
>>>
>>> PowerGadgets MVP
>>> http://www.powergadgets.com/mvp
>>> Blog:
>>> http://marcoshaw.blogspot.com
>>
>
Exchange 2003
"Shay Levi" <no@xxxxxx> wrote in message
news:8766a944dc8f8c9f8d832f421f0@xxxxxx
> What Exchange version?
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
>
>>
>> Thank you gentlemen. Why I want them? I'm pulling email information
>> from AD, to compare it to a "Global Alias" table kept on another
>> system. For each mail-enabled object, I need to hold two distinct
>> pieces of information. I thought a simple 2D associative array would
>> be the easiest to play with. If there's a better way to do this, I'm
>> all ears (eyes?). (I'm still quite new to PS but want to learn).
>>
>> "Brandon Shell [MVP]" <tshell.Mask@xxxxxx> wrote in message
>> news:68d19cd17078c9f65773edb050@xxxxxx
>>
>>> I would be more interested why you would feel the need for them.
>>> Being able to create Custom Objects, Arrays, and Hash tables I dont
>>> see the need for multi-dimensional arrays.
>>>
>>> I am not saying there isnt any, but so far everyone that has asked
>>> how to use hasn't needed them.
>>>
>>> Hello Marco Shaw [MVP],
>>>
>>>> Tim Munro wrote:
>>>>
>>>>> I've looked on the web in various places, but I am unable to figure
>>>>> out to create and manipulate multi-dimensional arrays in
>>>>> Powershell. Could some one post an explination and example please?
>>>>>
>>>>> Thanks.
>>>>>
>>>> From Lee Holmes' just-released Windows PowerShell Cookbook
>>>> (*everyone* should buy it!):
>>>>
>>> PSH>> $multi=@(
>>> PSH>>
>>>>>> (1,2,3,4),
>>>>>> (5,6,7,8)
>>>>>> )
>>> PSH>> $multi[0][1]
>>> PSH>>
>>>> 2
>>>>
>>> PSH>> $multi[1][3]
>>> PSH>>
>>>> 8
>>>>
>>>> That's one way, another requires you call a class from the .NET
>>>> framework.
>>>>
>>>> Lee's book explains this in greater details.
>>>>
>>>> Marco
>>>>
>>>> PowerGadgets MVP
>>>> http://www.powergadgets.com/mvp
>>>> Blog:
>>>> http://marcoshaw.blogspot.com
>
Interesting. What I ended up doing is very similar:
$dExchangeAddressList.Add($sKey,[array]($sValue1,$sValue2))
Thanks for your help. Looks like I'm on the right track.
--
Tim
"Brandon Shell [MVP]" <a_bshell@xxxxxx> wrote in message
news:BC7C4FAD-557C-43B8-A321-043EF7DC6D69@xxxxxx
>A hash table would be perfect.
>
> $mEnabled = @{} # creates a Hash table
> $mEnabled.Add($objName,$value1) # adds the mail enabled key
> $mEnabled.$ObjName += $value2 # adds second value to key
>
> You will get back a Hash table with the key as the Mail Enabled obj, and
> the value is an array with the values.
>
> "Tim Munro" <Excelsior@xxxxxx> wrote in message
> news:etBPf9qKIHA.4272@xxxxxx>
>> Thank you gentlemen. Why I want them? I'm pulling email information from
>> AD, to compare it to a "Global Alias" table kept on another system. For
>> each mail-enabled object, I need to hold two distinct pieces of
>> information. I thought a simple 2D associative array would be the
>> easiest to play with. If there's a better way to do this, I'm all ears
>> (eyes?). (I'm still quite new to PS but want to learn).
>>
>>
>> "Brandon Shell [MVP]" <tshell.Mask@xxxxxx> wrote in message
>> news:68d19cd17078c9f65773edb050@xxxxxx>>
>>>I would be more interested why you would feel the need for them. Being
>>>able to create Custom Objects, Arrays, and Hash tables I dont see the
>>>need for multi-dimensional arrays.
>>>
>>> I am not saying there isnt any, but so far everyone that has asked how
>>> to use hasn't needed them.
>>>
>>> Hello Marco Shaw [MVP],
>>>
>>>> Tim Munro wrote:
>>>>
>>>>> I've looked on the web in various places, but I am unable to figure
>>>>> out to create and manipulate multi-dimensional arrays in Powershell.
>>>>> Could some one post an explination and example please?
>>>>>
>>>>> Thanks.
>>>>>
>>>> From Lee Holmes' just-released Windows PowerShell Cookbook
>>>> (*everyone* should buy it!):
>>>>
>>> PSH>> $multi=@(
>>> PSH>>
>>>>>> (1,2,3,4),
>>>>>> (5,6,7,8)
>>>>>> )
>>> PSH>> $multi[0][1]
>>> PSH>>
>>>> 2
>>>>
>>> PSH>> $multi[1][3]
>>> PSH>>
>>>> 8
>>>>
>>>> That's one way, another requires you call a class from the .NET
>>>> framework.
>>>>
>>>> Lee's book explains this in greater details.
>>>>
>>>> Marco
>>>>
>>>> PowerGadgets MVP
>>>> http://www.powergadgets.com/mvp
>>>> Blog:
>>>> http://marcoshaw.blogspot.com
>>>
>>>
>>
Another option
$dExchangeAddressList.Add($sKey,@($sValue1,$sValue2))
"Tim Munro" <Excelsior@xxxxxx> wrote in message
news:OAwtBH5KIHA.2268@xxxxxx
> Interesting. What I ended up doing is very similar:
>
> $dExchangeAddressList.Add($sKey,[array]($sValue1,$sValue2))
>
> Thanks for your help. Looks like I'm on the right track.
> --
> Tim
>
> "Brandon Shell [MVP]" <a_bshell@xxxxxx> wrote in message
> news:BC7C4FAD-557C-43B8-A321-043EF7DC6D69@xxxxxx>
>>A hash table would be perfect.
>>
>> $mEnabled = @{} # creates a Hash table
>> $mEnabled.Add($objName,$value1) # adds the mail enabled key
>> $mEnabled.$ObjName += $value2 # adds second value to key
>>
>> You will get back a Hash table with the key as the Mail Enabled obj, and
>> the value is an array with the values.
>>
>> "Tim Munro" <Excelsior@xxxxxx> wrote in message
>> news:etBPf9qKIHA.4272@xxxxxx>>
>>> Thank you gentlemen. Why I want them? I'm pulling email information from
>>> AD, to compare it to a "Global Alias" table kept on another system. For
>>> each mail-enabled object, I need to hold two distinct pieces of
>>> information. I thought a simple 2D associative array would be the
>>> easiest to play with. If there's a better way to do this, I'm all ears
>>> (eyes?). (I'm still quite new to PS but want to learn).
>>>
>>>
>>> "Brandon Shell [MVP]" <tshell.Mask@xxxxxx> wrote in message
>>> news:68d19cd17078c9f65773edb050@xxxxxx
>>>>I would be more interested why you would feel the need for them. Being
>>>>able to create Custom Objects, Arrays, and Hash tables I dont see the
>>>>need for multi-dimensional arrays.
>>>>
>>>> I am not saying there isnt any, but so far everyone that has asked how
>>>> to use hasn't needed them.
>>>>
>>>> Hello Marco Shaw [MVP],
>>>>
>>>>> Tim Munro wrote:
>>>>>
>>>>>> I've looked on the web in various places, but I am unable to figure
>>>>>> out to create and manipulate multi-dimensional arrays in Powershell.
>>>>>> Could some one post an explination and example please?
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>> From Lee Holmes' just-released Windows PowerShell Cookbook
>>>>> (*everyone* should buy it!):
>>>>>
>>>> PSH>> $multi=@(
>>>> PSH>>
>>>>>>> (1,2,3,4),
>>>>>>> (5,6,7,8)
>>>>>>> )
>>>> PSH>> $multi[0][1]
>>>> PSH>>
>>>>> 2
>>>>>
>>>> PSH>> $multi[1][3]
>>>> PSH>>
>>>>> 8
>>>>>
>>>>> That's one way, another requires you call a class from the .NET
>>>>> framework.
>>>>>
>>>>> Lee's book explains this in greater details.
>>>>>
>>>>> Marco
>>>>>
>>>>> PowerGadgets MVP
>>>>> http://www.powergadgets.com/mvp
>>>>> Blog:
>>>>> http://marcoshaw.blogspot.com
>>>>
>>>>
>>>
>>>
>
| Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| User Control with 2-Dimensional Collection... | Christiano Donke | .NET General | 3 | 01 Apr 2009 |
| populating two dimensional array with excel data | Mecha77 | VB Script | 3 | 24 Jul 2008 |
| 2 dimensional array of objects | rotten | VB Script | 2 | 23 Jun 2008 |
| I hate "Dynamic multi-dimensional scrolling" | Luzius | Vista General | 7 | 19 Jun 2008 |
| Multi-dimensional ArrayList to ListBox with values | Dan | .NET General | 2 | 12 May 2008 |