Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Basically, I would like to create a hash table that looks like:

C++
{"ClassNumber" = $ClassNumber; "Student" = @($Student1,$Student2,...$Studentx)}

I would like to be able to add the ClassNumber, with a Student, then continue to add Students to the Student array one at a time, while leaving the same ClassNumber. Ie,
C++
$hash = {"ClassNumber" = $ClassNumber; "Students" = @($Student1)}

now add Student2, so it looks like
C++
{"ClassNumber" = $ClassNumber; "Students" = @($Student1,$Student2)}

until I have all Students, then add a new ClassNumber and associated Students.

I would also like to be able to access each one as follows:

C++
$hash["Class1"][0]
$hash["Class1"][1]
$hash["Class1"][2]
$hash["Class2"][0]
$hash["Class2"][1]
$hash["Class2"][2]
$hash["Class2"][3]
Posted
Updated 18-Jul-12 6:32am
v5

So then what's the problem? Any reason you can't use Dictionary[^] or Hashtable[^]? As far as I know, you can use .Net objects in PowerShell.
 
Share this answer
 
PS > $hash = @{}
PS > $hash['class1'] = @('student1')
PS > $hash['class1'] += 'student2'
PS > $hash

Name Value
---- -----
class1 {student1, student2}
 
Share this answer
 
I am not familiar with .Net objects, and was hoping to do it purely in powershell.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900