Feb 09 2022 11:08 AM
Hi people. I have a share on a machine that has more than 1kk files and the manual copy process becomes unfeasible. I know the command to move these files to another folder, but I would like to move only the files up to 11/2021.
All files have the same extension.
Thanks.
Feb 10 2022 12:29 AM
This searches for all bin files which have been saved before 01/11/2021 as example
Get-ChildItem -path "c:\temp" -Filter *.bin -Recurse | Where-Object Lastwritetime -lt '01/11/2021'
Feb 11 2022 06:13 AM
Hi @AngeloLobo_79,
The PowerShell script you need is as follows. The script is for files with .txt extension before the specified date.
$SourceFolder = "C:\OldFolder"
$DestinationFolder = "C:\NewFolder"
$Items = (Get-ChildItem -Path $SourceFolder -filter *.txt -Recurse | Where-Object LastWriteTime -lt '1/11/2021').Name
foreach ($Item in $Items)
{
Try {
Get-ChildItem -Path "$SourceFolder\$Item" | Move-Item -Destination $DestinationFolder
Write-Host "$Item file moved to $DestinationFolder folder."
}
Catch
{
Write-Host "$Item file could not be moved to $DestinationFolder folder."
}
}
Best Regards.
Feb 15 2022 04:40 AM
@AngeloLobo_79 Did our answers help ? @hasanemresatilmis included the file move part, I didn't because you said you already had that part 😉
Feb 15 2022 04:47 AM - edited Feb 15 2022 04:49 AM
Hi @Harm_Veenstra,
Yes. I wanted it to be all in one script so that people who don't know the move command can benefit from it. 🙂