嘿伙计们,所以我写了这个脚本来自动删除指定文件夹中的文件。
$oldTime = [int]25 # 0 days
$old2Time = [int] 10
foreach ($path in "C:\Test") {
Write-Host "Trying to delete files older than days, in the folder $path" -
ForegroundColor Green
# Write information of what it is about to do
Get-ChildItem $path -Recurse -Include "*.txt", "*.docx", "*.xlsx" #| WHERE
{($_.CreationTime -le $(Get-Date).AddDays($oldTime))} #| Remove-Item -Recurse -Force}
if ($_.CreationTime -le $(Get-Date).AddDays(-$oldTime))
{
Remove-Item -Recurse -Force
}
elseif ($_.CreationTime -le $(Get-Date).AddDays(-$old2Time))
{
Remove-Item -Recurse -Force
}
}
# deleting the old files
它以前工作过,我只检查一次并删除任何旧的东西。但是现在我希望它检查是否存在任何超过一定天数的文件,然后删除它们。如果不是,则检查超过另一个天数。但是当我运行它时,我得到“cmdlet Remove-Item at command pipeline position 1 Supply values for the following parameters: Path[0]:”
有谁知道我做错了什么?谢谢