Function Move {
#Moves all files older than 31 days old from the Source folder to the Target
Get-Childitem -Path "E:\source" | Where-Object { $_.LastWriteTime -lt (get-date).AddDays(-31)} |
ForEach {
Move-Item $_.FullName -destination "F:\target" -force -ErrorAction:SilentlyContinue
}
}
在源目录中是大于2 - 3年的文件,但是当我运行脚本时,没有任何操作移动到目标目录?怎么了 ?将文件大于31天移动到另一个驱动器
如果您取出ErrorAction,是否会产生任何错误? – 2011-05-06 13:25:24
您的文件是否正确地存在于'E:\ source'或其子目录中?在后一种情况下,使用'Get-Childitem -Recurse' – 2011-05-06 15:54:53
FYI,这将不会移动子目录中的文件。 – JasonMArcher 2011-05-06 15:56:20