Looping through a hashtable referencing a second hashtable

I am trying to write a script to back up user data. I have two hashtables, one named $Locations that contains the directory name and the corresponding directory location (e.g. “Data” = “C:\Data”), and a hashtable named $Destinations that contains the destination pairs built from user responses (e.g. “Data” = “D:\Data”. I cannot figure out how to loop through the $Locations hashtable and reference the $Destinations hashtable at the same time. If I use the below code, it gives me the $Locations data as I want it, but I cannot do anything with the $Destinations.
[pre]ForEach ($Source in $Locations.Values) {
Write-Host $Source
}[/pre]
If I leave off the .Values in the ForEach, so that I can try to reference the Destination, then I just get one big blob of all the data separated by spaces. Advice is greatly appreciated, thanks.

What are you actually trying to do with these hashtables. Can you explain the actions you would perform with these hashtables in bullet points below for us to understand it.

I am trying to loop through them for source/destination pairs and pass that to Robocopy.

Shortly after I posted this, it hit me to use the following:

Assuming the $Locations hashtable has an entry “Data” = “C:\Data” and the $Destinations hashtable ends up having an entry of “Data” = “D:\Data” after user input. I ran through the following loop:

[pre]ForEach ($Source in $Locations.Keys) { Robocopy $Locations[“$Source”] $Destinations[“$Source”] }[/pre]

and it came out with my desired line, “Robcopy C:\Data D:\Data”

.Keys ended up being the property I was looking for.

Thanks for the replies!

Great to know that you figured it out yourself.