Aqui está um script simples do PowerShell que fará o que você está procurando. Altere FolderA
e FolderB
apropriadamente. Além disso, o -whatif
apenas informará o que ele fará sem executar nenhuma ação. Depois que você verificar que está tentando corrigir, basta remover o -whatif
.
#This sets $FolderA to the directory you want to copy from
$FolderA = "v:\FolderA"
#This sets $FolderB to the directory you want to copy to
$FolderB = "v:\FolderB"
#This does the copy (Note the -whatif to make sure this is what you want)
Copy-Item -Path "$FolderA\*" -Destination $FolderB -WhatIf
#This does a compare of Directory A and B, and removes all files that only exist in Directory B that haven't been access for 7 days. (Again, notices the -whatif at the end)
Compare-Object (Get-ChildItem $FolderA) (Get-ChildItem $FolderB) ' #The ['] tells PowerShell the command will continue on the next line
| where {$_.SideIndicator -eq "=>"} '
| where {$_.InputObject.LastWriteTime -le (Get-Date).Adddays(-7)} '
| Foreach { Remove-Item -Path $_.InputObject.FullName -WhatIf}