Moving contents of source to destination with similar name

I have a weird problem, looking for the Powershell solution, but haven’t figured out the syntax yet…

I have a directory full of almost 40k folders. It used to be only 20k, but due to a new folder naming convention from an attached application, each folder got duplicated with a new name. They look like this:

C:\Directory\Subfolder1 {dd-12345}

NOTE - Subfolder1 {dd-12345} has a random assortment of numbers and letters, but will always be appended with “{dd-”, and always closes with “}”

Subfolder1 has contents in it that I need to migrate to Subfolder1 {dd-12345}. Essentially I want my script to do this:

  1. Get-Childitem ‘C:\Temp\SourceFolders*’ -Recurse
  2. For each folder, match the folder with a similar name and move the contents from the source folder (Subfolder1) to destination folder (Subfolder1 {dd-12345}).
  • This is the piece I can’t figure out the logic for…struggling trying to use a match function with a foreach statement.
  1. Remove-Item 'C:\Temp\SourceFolders\Subfolder1 -Recurse

Any help would be appreciated, thanks.

Easy … look for folders with the desired pattern {dd-12345}, then split their name from this pattern and you have your folder you want to move into them. Or did I miss something? :man_shrugging:t4: