[Solved] Combine two dictionaries and replace keys with values in powershell

jsss Asks: Combine two dictionaries and replace keys with values in powershell
i have two arrays that look like this:

$ht1 = @{

"computer55" = "port33"

“computer1” = “port1”

“computer2” = “port2”



$ht2 = @{

"A1:B2:C3:D4:E5:F6" = "port1"

"A2:B3:C4:D5:E6:F7" = "port2"

"A3:B4:C5:D6:E7:F8" = "port33"

"A4:B4:C5:D6:E7:F8" = "port45"

The first one is one I manually hardcode into the script, I have an actual list of device names and what port they are plugged into on a switch. The second one is generated with a switch script that logs in, gets the mac address table and records it as a hashtable.

My desired outcome is this, if there is a port with an assigned name, replace the port name with the device name.

$ht3(or any name) = @{

"A1:B2:C3:D4:E5:F6" = "computer1"

"A2:B3:C4:D5:E6:F7" = "computer2"

"A3:B4:C5:D6:E7:F8" = "computer55"

"A4:B4:C5:D6:E7:F8" = "port45"

I’ve somehow spent about a day on this(… pretty much the first powershell script I’ve ever came up with) and my end result is always the same, I end up merging two hashtables and pair the port with the computer name and not the mac address with the computer name. any direction is appreciated

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.