![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br>
|
|
|||||||
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||
|
Guest
Posts: n/a
|
Hello,
I have a very deeply nested directory structure which is part of a loadbuild system. Because our loadbuild machine periodically runs out of space, I would like to run a scheduled task which deletes old build artifacts. So, how can I make a powershell script which deletes (recursively) directories which are older than X days? I'm not that familiar with the ..NET APIs, which is (I think) why I'm running into trouble on this one. Thanks for the help. I imagine this is pretty easy for powershell veterans. |
||
|
|
|
|
|
|
#2 | ||||||||||||||
|
Guest
Posts: n/a
|
David Stuart wrote:
files: PS C:\Program Files> get-childitem . -rec| ` where-object{$_.psiscontainer -and ($_.lastwritetime -lt "01/01/2008")} Now to actually delete (just add this to the above command): |foreach-object{remove-item $_ -recurse -whatif} -whatif so you can check out what would be deleted. You can do a start-transcript, run the above with the -whatif, stop-transcript, then review the log of what should be deleted to make sure if meets your requirements. Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
||||||||||||||
|
|||||||||||||||
|
|
#3 | ||
|
Guest
Posts: n/a
|
Get-ChildItem -Recurse -Path .\* |
where{ ($_.mode -match '^d.*') -and (([datetime]::Today-$_.CreationTime.Date).Days -gt X) } | %{ Remove-Item $_ } It's all one line. Replace X for real value of days and .\* for real path. |
||
|
|
|
#4 | ||||||||||||||
|
Guest
Posts: n/a
|
On Mon, 14 Apr 2008 20:30:49 -0700, ajax76 wrote:
That did the trick! |
||||||||||||||
|
|||||||||||||||
|
|
|
|