我已经研究过了,但是还没有遇到可以使我正确执行有关脚本的事情,该脚本可以执行以下操作:
-enumerate over a folder of profiles
-check a one level down to see if a certain subfolder exists
-if it exist
-check last modified date
-if older than jan 1, 2015, delete files AND the folder
-write the user's profile name and files deleted to a log file
-if not older than jan 1, 2015, do not delete
-write the user's profile name to a log file
文件结构看起来像这样
-profiles
-name1
-folder1
-folder2
fileOlderThanXDate.old
-name2
-folder1
-folder2
fileNewerthanXdate.new
-name3
-folder1
因此,在配置文件中,向下搜索名称1,然后搜索文件夹1(每个人都会拥有),如果有文件夹2,请检查其中文件的lastModifiedDate(如果旧的话),删除文件AND文件夹2,然后输入name1和那些文件到日志。继续到name2,似乎在folder1中为folder2,但是该文件是较新的,然后只需将name2写入另一个日志即可。继续到name2,文件夹1中没有文件夹2,继续
我发现所有提示和碎片到文件夹中并删除,如果文件存在时间超过x天,则删除,但是我无法将拼图碎片拼凑在一起。这是一个问题,但请您向任何方向进行推动...否则,对我来说,这是很多单击和删除操作。
您需要一个简单的ForEach循环和Test-Path cmdlet(假定PSv3或更高版本)。我也将Split-Path用于输出到日志。
Switch(Get-ChildItem C:\Users -Directory|Select -Expand FullName){
{!(Test-Path $_\Folder1\Folder2)}{Continue}
{Test-Path $_\Folder1\Folder2\* -OlderThan "10/01/2014 12:00 AM"}{Split-Path $_ -Leaf|Out-File Old.txt -Append;Remove-Item $_\Folder1\Folder2 -Recurse -Force;continue}
default {Split-Path $_ -leaf | Out-File NotOld.txt -Append}
}
编辑:我\*
在第二个切换条件下添加到路径的末尾,因此它将查看Folder2内的文件,而不是查看Folder2的修改日期。现在,将查看该文件夹中是否有旧文件,以及是否删除整个文件夹并将其名称输出到Old.txt日志文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句