Forum Discussion
AngeloLobo_79
Feb 09, 2022Copper Contributor
Script to Move Folder Files
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 ...
Feb 11, 2022
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.