Skip to content

Instantly share code, notes, and snippets.

@MartinMiles
Last active June 15, 2025 12:22
Show Gist options
  • Save MartinMiles/d5545df128706264d1ee6c8a0ade300a to your computer and use it in GitHub Desktop.
Save MartinMiles/d5545df128706264d1ee6c8a0ade300a to your computer and use it in GitHub Desktop.
# Moves page items in bulk preserving the IDs (here's one level up, but could be anything, but did not work between databases):
param(
[string]$SourceDatabase = "master",
[string]$SourcePath = "sitecore/content/Zont/Habitat/Home/Home",
[string]$DestinationDatabase = "master",
[string]$DestinationPath = "sitecore/content/Zont/Habitat/Home"
)
# 1. Ensure both PS drives exist
if (-not (Get-PSDrive -Name $SourceDatabase -ErrorAction SilentlyContinue)) {
New-PSDrive -Name $SourceDatabase -PSProvider Sitecore -Root "\" -Database $SourceDatabase | Out-Null
}
if (-not (Get-PSDrive -Name $DestinationDatabase -ErrorAction SilentlyContinue)) {
New-PSDrive -Name $DestinationDatabase -PSProvider Sitecore -Root "\" -Database $DestinationDatabase | Out-Null
}
# 2. Build drive-qualified paths
$sourceRoot = "$SourceDatabase`:\" + $SourcePath
$destRoot = "$DestinationDatabase`:\" + $DestinationPath
# 3. Create destination folder if needed
if (-not (Test-Path $destRoot)) {
New-Item -Path $destRoot -ItemType Directory -Force | Out-Null
Write-Host "Created destination: $destRoot"
}
# 4. Move each child folder/item under source into the destination
Get-ChildItem -Path $sourceRoot | ForEach-Object {
$child = $_
$targetPath = Join-Path -Path $destRoot -ChildPath $child.Name
if (-not (Test-Path $targetPath)) {
Move-Item -Path $child.PSPath `
-Destination $destRoot `
-Force
Write-Host "Moved: " $child.PSPath "→" $destRoot
}
else {
Write-Host "Skipped (already exists):" $targetPath
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment