Quantcast
Channel: Brian Pedersen's Sitecore and .NET Blog
Viewing all articles
Browse latest Browse all 285

Create Sitecore items using PowerShell

$
0
0

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:


Viewing all articles
Browse latest Browse all 285

Trending Articles