8

What is the easiest and quickest way to copy an item to various locations?

I have about 100 multisites in a solution and I have created a new template. I need to create a new item inheriting this template in each of the site. Is a Powershell script the best solution? Perhaps add a script to the item context menu that allows the user to insert a new item using that template to all the multisites? If so, can I add an option for the user to enter the name they would like to use to create the new item?

2 Answers 2

8

SPE is likely going to be your best lower effort approach. The book provides several examples for creating Context Menu options and prompting for input.

Script Integration

Creating

New-Item allows for the creation of items at a path using the specified template.

Copying

Copy-Item will be the go-to command for copying items. Call it for each destination. Perhaps not needed if you are only concerned with new items.

Input Dialogs

One option for input is to use Show-Input to request a value from the user.

Read-Variable is another option if you want a more sophisticated dialog for users, especially when more knobs and levers are required.

Show-Input "Please provide 5 characters at most" -MaxLength 5

Show Input

Documentation

I recommend you explore the book for a few minutes then let your imagination run wild.

If this is your first time using SPE then start in the PowerShell ISE and run some simple commands. You can save the script in the Script Library and later add it to the Content Editor integration. The book walks you through just about everything you need to get this working.

The Slack channel #module-spe is another good resource for discussion.

0
1

If you just want create a new item based on specific template, you can try the below powershell script.

PowerShell script

This will create item based on specific template, with the name added in the script, however if you want more flexibility, as Michael mentioned, you should definitely read the book and explore.

Please see sample script for ref:

Get-Item master: -Query "/sitecore/content//*[@@templatename='Home Page']" | ForEach-Object {
    $newpath= $_.FullPath
    $item = New-Item $newpath -Name ItemName  -type "/sitecore/templates/Event"
}

Let me know if this helps.

2
  • When including code, could you add it in as a code snippet in the text? It then becomes searchable and also helps with readability / accessibility.
    – Kasaku
    Commented Dec 8, 2017 at 10:09
  • Sure, i will keep this in mind going forward. Commented Dec 8, 2017 at 10:29

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.