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.
goldcream76Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
Always best to show what you have so that those who might try to help don't have to recreate what might already be working (it also shows that you've put some actual effort into the issue and are invested).
However, this isn't too complex...
$cutoff = (Get-Date).AddDays(-45).Date
Get-ChildItem -Path C:\Clients -Filter "Common" -Recurse -Directory | ForEach `
{
    Get-ChildItem -Path $_.FullName -File -Recurse |
     Where { $_.CreationTime -lt $cutoff }
} | Remove-Item -WhatIf

Open in new window

Remove the -whatif parameter to run for real.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
goldcream76Author Commented:
Thanks this does exactly what I was asking for
0
Senior IT System EngineerIT ProfessionalCommented:
Thanks for the script Foo :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.