0

I have exported items using Export-Item command to a specific path in Data folder say, "websitepath/data/batch/userGivenName", please refer my previous question How to copy selected items to a Data folder using powershell script? now I have to read the items from this folder. The items under folder are in .item extension. I am able to get items using $items = Get-ChildItem -Path "websitepath\Data\batch\sample", but the items are not deserialized.

I tried using, Import-Item but its returning empty list, how do I deserialize/convert them?

$items = Get-ChildItem -Path "websitepath\Data\buckets\sample"
$list=@();
$items|Foreach{
    $itemPath="websitepath\Data\buckets\sample\"+$_.BaseName
    $list+= Import-Item -Path $itemPath -Root "websitepath\Data\buckets\"
   Write-Host($list)
}
if($list.Count -eq 0) {
    
    Show-Alert "There are no items currently added to the batch."
    
} 
else {
 $list | Show-ListView 
   
}
Close-Window

I referred following file for Import-Item, https://doc.sitecorepowershell.com/appendix/packaging/import-item-1

Any guidance would be helpful.

2
  • Does the deserialization work using the Sitecore Ribbon commands? This will help determine if there is an issue with the script or something else. May 3 at 14:05
  • I guess the issue is with the script, as I noticed the import-items created items under "Sitecore/Content" folder by default as the item path I have provided didnt match with sitecore content tree structure May 4 at 7:14

1 Answer 1

0

To test the same scenario, I did the following on my local.

  • I created two items in the content tree like this.

enter image description here

  • I exported the items using the Export-Item. And it looks like this

enter image description here

  • I deleted the items in the content tree and then I run this command to import the items using Import-Item in PowerShell like this.

    Import-Item -path "C:\inetpub\wwwroot\Sitecore10.1sc.dev.local\App_Data\serialization\master\sitecore\content\Home" -root "C:\inetpub\wwwroot\Sitecore10.1sc.dev.local\App_Data\serialization\" -recurse

And then it created those items in the content tree.

I think, if you want to import the items, In place of using a loop, you can use recursive and you need to provide the folder path from where you need to import the items. For example, I am exporting items inside the Home folder.

Hope this helps.

1
  • Hi Sumit, I didn't want the items to be created again in the content tree. I tried to convert them back to item as they were in ".item" extension. I guess I have used the wrong command to achieve this. As the Import-Item created items under "Sitecore/Content" folder as the path provide doesn't match with the content structure. May 4 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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