goldcream76
asked on
Need a powershell script to delete files 45 days or older in path recursively but only in subfolders named "common"
We have a Directory structure like below
C:\Clients\Client1
-User
-System
-Common
-FolderA
-FolderB
-FolderC
\Client2
-User
-System
-Common
-FolderA
-FolderB
-FolderC
I need a script that can recursively look through the C:\Clients\ folder and locate the "common" folder in each Clients subfolder and delete all files with a creation date of 45 days or older in the "Common" directory and all subfolders in that directory. It needs to leave all files in the User and System folders and subfolders alone. I've tried various things but my powershell scripting is really limited and the best I've been able to accomplish is a powershell script that deletes all files 45 days or older and leaves the actual system and users folder alone but still deletes files in subfolders of system and users. Hope that all makes sense....any help is appreciated...Thanks.
C:\Clients\Client1
-User
-System
-Common
-FolderA
-FolderB
-FolderC
\Client2
-User
-System
-Common
-FolderA
-FolderB
-FolderC
I need a script that can recursively look through the C:\Clients\ folder and locate the "common" folder in each Clients subfolder and delete all files with a creation date of 45 days or older in the "Common" directory and all subfolders in that directory. It needs to leave all files in the User and System folders and subfolders alone. I've tried various things but my powershell scripting is really limited and the best I've been able to accomplish is a powershell script that deletes all files 45 days or older and leaves the actual system and users folder alone but still deletes files in subfolders of system and users. Hope that all makes sense....any help is appreciated...Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the script Foo :-)
ASKER