Powershell: Move Files recursively Powershell: Move Files recursively powershell powershell

Powershell: Move Files recursively


You could replace the Move-Item command with an Copy-Item command and after that, you can delete the files you moved by simply calling Remove-Item:

$a = ls | ? {$_.Name -notlike "ProjectXXX.*" -and $_.Name -ne "config.log4net" -and $_.Name -ne $binFolderName }$a | cp -Recurse -Destination bin -Forcerm $a -r -force -Confirm:$false


As already stated, Move-Item will not overwrite folders so you're left with copying. An alternative solution would be to call Robocopy for each file in your for-each loop with the /MOV switch (amongst others!); this will move then delete the source file.