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