首页 > 系统服务 > 详细

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

时间:2016-09-22 18:22:27      阅读:452      评论:0      收藏:0      [点我收藏+]
#定义执行的目录
$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天之前的文件

原文:http://timefiles.blog.51cto.com/8475652/1855352

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!