Powershell 查找删除30天之前的文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Powershell 查找删除30天之前的文件相关的知识,希望对你有一定的参考价值。

#定义执行的目录
$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

#删除30天之前修改的文件:
Get-ChildItem -Path $path -Recurse -ErrorAction:SilentlyContinue | `
Where-Object -FilterScript {(((get-date) - ($_.LastWriteTime)).days -gt 30 `
-and $_.PsISContainer -ne $False)} | Remove-Item -Recurse

#删除30天之前修改的文件(包括删除只读、隐藏):
#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


本文出自 “汜水流年_” 博客,请务必保留此出处http://timefiles.blog.51cto.com/8475652/1855352

以上是关于Powershell 查找删除30天之前的文件的主要内容,如果未能解决你的问题,请参考以下文章