Skip to content

Instantly share code, notes, and snippets.

@brianvanderlugt
Created August 26, 2019 15:59
Show Gist options
  • Save brianvanderlugt/d53847a0d9d45b849f710ed2c8c7045a to your computer and use it in GitHub Desktop.
Save brianvanderlugt/d53847a0d9d45b849f710ed2c8c7045a to your computer and use it in GitHub Desktop.
Moves directories relatively to a new location
$directoriesToMove = 'Backup'
$newDirectory = 'C:\target\directory'
(Get-ChildItem -Recurse -Path $directoriesToMove -Directory) | foreach{
$newPath = $($_.FullName.Replace("$PWD", $newDirectory));
$newPath = $newPath.Substring(0, $newPath.LastIndexOf('\'));
New-Item -Path $newPath -ItemType Directory | Out-Null;
Move-Item -Path $_.FullName -Destination $newPath}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment