Since a year has already passed in the meantime … Are you still a PowerShell rookie?
Could you please go back, edit your question once again and fix the formatting of your ocde?
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
You’re right, I changed the formatting to highlight the codeblock.
As for being a rookie, well, the problem seems to be advanced for me but not sure if it is indeed that hard for other people
Just because you name something $hash it does not magically turn into a hashtable. In fact you’re explicitly creating a [PSCustomObject].
How does the output look like when you simply output the variable $hash to the console?
Regardless of that … if you have proper XML files I would mess with regex. Instead I’d use the built in ability to actually read the XML and turn it in to a hierarchical object structure.
I’d start with outputting the result of the Where-Object filter to the console before I pipe everything to a potentially risky cmdlet. … or at least add a -WhatIf to the Move-Item command.