My problem may\may not be complicated but I have been scratching my head and searching for a way to do this but so far have not come up with much.
I have a folder structure like so:
C:\
└───ParentFolder
├───ChildFolder1
│ ├───SubFolderA_1
│ ├───SubFolderA_2
│ ├───SubFolderA_3
│ ├───SubFolderA_4
│ ├───SubFolderB_1
│ ├───SubFolderB_2
│ ├───SubFolderB_3
│ └───SubFolderB_4
└───ChildFolder2
├───SubFolderA_1
├───SubFolderA_2
├───SubFolderA_3
├───SubFolderA_4
├───SubFolderB_1
├───SubFolderB_2
├───SubFolderB_3
└───SubFolderB_4
What I'm looking for is a PowerShell script that would utilize the serialized nature of the "SubFolders" names to delete older versions, leaving only the most recent SubFolders in place.
Using the example above, this would mean the script would delete SubFolderA_1 to SubFolderA_3 and SubFolderB_1 to SubFolderB_3, leaving only SubFolderA_4 and SubfolderB_4 in the ChildFolders.
Would anyone know a way of doing this? I was thinking about Object Sorting + The Recursive Function + pattern matching, but I don't seem to get anywhere with it. I'm a PS noob by the way.
Your help would be much appreciated.