Create Sitecore items using PowerShell

You can use the Sitecore PowerShell Extensions for many trivial tasks. This script creates a “components” folder below all items from a root item:

// Get the root item
$root = Get-ChildItem -Path "master:/sitecore/content/site/root"
// Loop through all children of the root item
foreach ($item in $root) {
    // Skip if the folder already exists
    if (@(Get-Item -Path "master:" -Query "$($item.ItemPath)/components").count -gt 0) {
	    Continue
    // Create new item
	} else {
        New-Item -Path $item.ItemPath -Name "components" -ItemType "/sitecore/templates/Common/Folder"
    }
}

This script was created by my colleague Adam Honore, when I realized that I had forgot to include a “components” folder in my Sitecore master – after I had created my 100+ items. Thanks to Adam for the help.

MORE TO READ:

Advertisements

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in Sitecore, Sitecore 7, Sitecore 8, Sitecore 9 and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.