PowerShell-按修改日期删除特定文件夹中的文件

问题描述

从源头上读取内容无效,或者我什至不确定是否一切正常。.需要您的帮助。

谢谢!

$Src = C:\Users\Asus\Documents\PowerShell\Folder.txt

Get-ChildItem –Path $Src -file -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-30))} | Remove-Item -Whatif

Folder.txt上的内容

New Folder

New Folder(2)

解决方法

尝试使用:

$Src = "C:\Users\Asus\Documents\PowerShell\Folder.txt"
Get-ChildItem –Path (Get-Content $Src) -file -Recurse