Powershell - Delete subfolder(s) in folder with specific name(s) older than 30 days -


stackoverflow, trying come posh script specific task has me beating head against desk here. pretty new powershell, , need here.

here trying accomplish:

i need able search through drive specific folder called "30 day toss" , delete subfolder(s) inside of has creationdate of on 30 days old.

example:

p:\project\2014\3d1004\plan 1\30 day toss\archive1

p:\project\2014\3d1004\plan 2\30 day toss\04-12-2014

the archive1 folder above created 10 days ago , doesn't need deleted. 04-12-2014 folder above created on 30 days ago , needs deleted, along files/folders under it.

the project, year, job number , plan number variable , change, hard coding search path isn't option.

any assistance appricieated, thanks!

ok, assuming folder structure same, , want 6th level of folder or subfolders of that, work:

gci p:\ -directory -recurse | ?{$_.fullname -match ".:\\.+?\\.+?\\.+?\\.+?\\.+?\\" -and $_.creationtime -lt (get-date).adddays(-30)}|remove-item -recurse -whatif 

that looks @ entire p: drive folders, if folder name is:

p:\<anything>\<anything>\<anything>\<anything>\<anything>\<anything> 

it checks see if created on 30 days ago, , if deletes , of it's contents. has have many levels script @ it.

edit: ok, let's change little. if folder we're looking inside of called "30 day toss" we'll folders name, , pull listing of things inside each of them. easy enough! first, code:

gci p:\ -directory -recurse | ?{$_.name -ieq "30 day toss"} | %{gci $_.fullname | ?{$_.creationtime -lt (get-date).adddays(-30)} | remove-item -recurse -force} 

then break down little.

first listing of folders on p: drive. select ones named "30 day toss" (not case sensitive).

for each folder find name pull directory listing whatever inside folder, , select things older 30 days. each of things older 30 days delete them, , inside them.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -