Last active
August 22, 2022 02:58
-
-
Save nehemiahj/440416aabc8d1080fa5165d3f8fab28b to your computer and use it in GitHub Desktop.
Sitecore PowerShell Move Items in Bulk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Move Bulk of Selected Items to Desitnation Folder | |
.NOTES | |
NEHEMIAH JEYAKUMAR | |
#> | |
$dropDownSelector = Get-Item -Path "master:\sitecore" | |
$dialogParams = @{ | |
Title = "Move Mutliple Items to Destination Folder" | |
Description = "This script will let you to move multiple items to a destination folder." | |
OkButtonName = "Move" | |
CancelButtonName = "Close" | |
Width = 900 | |
Height = 500 | |
ShowHints = $true | |
Parameters = @( | |
@{ | |
Name = "itemsToMove" | |
Title="Items to move" | |
Source="DataSource=/sitecore&DatabaseName=master&ExcludeItemsForDisplay={EB2E4FFD-2761-4653-B052-26A64D385227},{13D6D6C6-C50B-4BBD-B331-2B04F1A58F21},{B701850A-CB8A-4943-B2BC-DDDB1238C103},{3C1715FE-6A13-4FCF-845F-DE308BA9741D}" | |
Editor="treelist" | |
Tooltip = "Select from content items to move" | |
}, | |
@{ | |
Name = "destinationFolderItem" | |
Title = "Destination Folder" | |
Editor = "droptree" | |
Source = "/sitecore" | |
Tooltip = "Select from destination folder from only content or media folder" | |
} | |
) | |
} | |
$dialogResult = Read-Variable @dialogParams | |
#TODO: Optimize it further | |
if($dialogResult -ne "ok") | |
{ | |
Exit | |
} | |
if ($itemsToMove -and $destinationFolderItem){ | |
if ($itemsToMove.Count -gt 0 -and $destinationFolderItem.Count -eq 1 -and ($destinationFolderItem.Paths.FullPath.StartsWith("/sitecore/content") -or $destinationFolderItem.Paths.FullPath.StartsWith("/sitecore/media library") )){ | |
ForEach ($mItem in $itemsToMove) { | |
if ($destinationFolderItem.Paths.FullPath.StartsWith($mItem.Paths.FullPath) ){ | |
Show-Alert "You cannot move parent item to a child item. Choose different Destination folder." | |
Exit | |
} | |
if ($destinationFolderItem.Paths.FullPath.StartsWith("/sitecore/content") -and $mItem.Paths.FullPath.StartsWith("/sitecore/media library")){ | |
Show-Alert "You cannot move media item to a content folder." | |
Exit | |
} | |
elseif ($destinationFolderItem.Paths.FullPath.StartsWith("/sitecore/media library") -and $mItem.Paths.FullPath.StartsWith("/sitecore/content")){ | |
Show-Alert "You cannot move content item to a media folder." | |
Exit | |
} | |
} | |
$response = Show-Confirm -Title "Do you wish to move items?" | |
if ($response -eq "yes") | |
{ | |
$itemsToMove | ForEach-Object { | |
Move-Item -Path $_.ItemPath -Destination $destinationFolderItem.Paths.FullPath; | |
Write-Host "Item moved to: "$_.ItemPath; | |
} | |
Show-Alert "Selected items have been moved to Destination Folder." | |
} | |
} | |
else { | |
Show-Alert "Destination Folder (Only Content or Media folder) and the items to be moved should be populated." | |
Exit | |
} | |
} | |
else { | |
Show-Alert "Destination Folder (Only Content or Media folder) and the items to be moved should be populated." | |
Exit | |
} | |
Close-Window |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment