2

I have a requirement where I need to get items from a Bucket and move them into another Bucket.

When I manually move the item using MoveTo from the menu, it works fine and shows a perfect tree structure in Bucketable item format like this.

enter image description here

But when I try to do that using a Powershell script then it shows as a normal item that doesn't come in the Bucketable structure. It shows like this.

enter image description here

The script I am using is this.

$destinationItem  = Get-Item "/sitecore/media library/folder1/folder2/Videos"

$rootOfitemsToMove = Get-ChildItem -path "/sitecore/media library/folder1/folder2/folder3/Media Content/2018/05/21/19/52" -Recurse | Where-Object { $_.TemplateName -ne 'Bucket' } 

$rootOfitemsToMove | ForEach-Object {
   Move-Item -Path $_.ItemPath -Destination $destinationItem.Paths.FullPath 
}

Please let me know if I need to add something to Powershell script?

2
  • did you try to sync them after moving them from powershell? Commented May 18, 2022 at 10:57
  • Wondering why Move-To works without sync and why Move-Item is not Commented May 19, 2022 at 15:17

2 Answers 2

4

You need to click on the sync button, then it will automatically move into the Bucketable structure. Make sure to click on parent folder and then click on the sync button, in your case click on the Videos Item.

enter image description here

Although not sure why we need to do it manually, I can find this way only for now.

1
  • 1
    Thanks @Gaurav That worked for me Commented May 18, 2022 at 13:37
1

To sync the bucket via PowerShell, you can call the BucketManager.Sync() function.

[Sitecore.Buckets.Manager.BucketManager]::Sync($destinationItem);

Call that after your script is run. You may want to use an EventDisabler as this can be an expensive and time consuming call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.