techthoughts2
5/31/2017 - 3:57 PM

Move files

Move files from one directory to a different directory. Then remove the original folder

#gets all origin files and moves them to destination path.
#---------------------------------------------------------
$origPath = 'C:\Users\username\Desktop\images\files'
$destPath = 'C:\destfolder\foldertest'
#---------------------------------------------------------
Write-Output "Moving files..."
Write-Output "From: $origPath"
Write-Output "To: $destPath"
try {
    Get-ChildItem -Path $origPath -Recurse -File  -ErrorAction Stop | `
        Move-Item -Destination $destPath -ErrorAction Stop
    Write-Output "File move completed."
    Write-Output "Removing original directory."
    #removes orignal directory
    Remove-Item $origPath    
    Write-Output "Original directory removed."
}
catch {
    Write-Output "An error was encountered:"
    Write-Error $_
}