#定义执行的目录 $path = "D:\logfile\" #获取30之前修改的文件列表:get-childitem -path $path -recurse - erroraction:silentlycontinue | ' where-object -filterscript {((get-date) - ($_. lastwritetime)) .days -gt 30 '-and $_. psiscontainer -ne $False)} | select-object fullname #PsISContainer =true is file,false is folder# deleted files modified 30 days ago:get-childitem -path $path -recurse - erroraction:silentlycontinue | ' where-object -filterscript {((get-date) - ($_. lastwritetime)) .days -gt 30 '-and $_. psiscontainer -ne $False)} | remove-item -recurse# Delete files modified 30 days ago (including delete read-only, hidden): # get-childitem -path d:\test -force -recurse -erroraction:silentlycontinue | ' #Where-object -filterscript {((get-date) - ($_. creationtime)) .days -gt 30 ' #-and $_. Psiscontainer -ne $True)} | remove-item -force
This article is from the "BOM water Year _" blog, please be sure to keep this source http://timefiles.blog.51cto.com/8475652/1855352
Powershell find deleted files up to 30 days ago