Given a PowerShell array hashtable1 similar to the following:
$dept= @{
'Sales' = @{
'SAM' = 'Manager'
'SAP' = 'Person'
}
'IT' = @{
'ITM' = 'Manager'
'ITS' = 'Specialist'
'ITT' = 'Technician'
'ITC' = 'Consultant'
}
}
If enter the following in the console:
$dept.it.itc
$dept.sales.sam
I get:
Consultant
Manager
Which is as expected.
However, what I'd like to do is something like
write-host $dept.itc
write-host $dept.sam
and get
IT Consultant
Sales Manager
in return.
I'm looking for a sort function to do a 'reverse traversal' of the array because 'IT', 'Sales' etc are the OU's I need to put new users into. There are many more OU's that I have removed for brevity.
[1] An array is simply a list of values and a hashtable is a collection of key/value pairs similiar to Javascript's JSON or Python's dict.