复制 45 天前的文件,验证然后删除



尝试使脚本正常工作,该脚本可以将 45 天前的文件复制到新的网络位置,验证它们已复制,然后从原始位置删除这些文件。任何帮助都非常感谢

  1. 这将获取文件夹中的所有子项(文件夹和文件( 获取子项递归
  2. 选择早于 45 天 $_LastWriteTime -lt(获取日期(的项目。添加天数(-45(
  3. 将它们移动到新位置移动项目目标
  4. 删除旧项目 删除项目

    get-childitem -path "C:\HERE" -Recurse | where-object {$_.LastWriteTime -lt (get-date(.添加天数(-45(} |移动项目标 "\D:\THERE" |删除项目

更新 8/12/2017 已添加 验证文件在删除之前是否已移动。if(测试路径 $Destination$($_.名称((

$Source = "C:Source"
$Destination = "D:Destination"
get-childitem -Path "C:Source" -Recurse | where-object {$_.LastWriteTime -lt (get-date).AddDays(-45)} | move-item -destination "D:Destination" -force | ForEach-Object{
if(Test-Path $Destination$($_.Name)){
Remove-Item $_ -Force
}
}

更新 8/14/2017 全部在一行中

get-childitem -Path "C:Source" -Recurse | where-object {$_.LastWriteTime -lt (get-date).AddDays(-45)} | move-item -destination "D:Destination" -force | ForEach-Object{ if(Test-Path $Destination$($_.Name)){Remove-Item $_ -Force}}

相关内容

最新更新