How to work with Sitecore items in PowerShell extensions?
Reading some of the blogs from the Sitecore community I find it pretty apparent that we didn?t do a great job advocating the optimizations that PowerShell Extensions have introduced for working with Sitecore items. This blog attempts to rectify this problem to a degree.
When to use the options flag in PowerShell?
Initiates the default workflow, if any. Options flag used when copying from one database to another. Matches the item by ItemUri. Specifies the version to include. Legend: “–” – not applicable; “✓” – available. Below we will show how to use each command with the Windows PowerShell syntax followed by some examples of the common C# equivalent.
How are custom parameters added to PowerShell commands?
Due to the nature of Windows PowerShell, commands such as these are extended with custom parameters and switches using Dynamic Parameters. These parameters are then added to the command at the time of use and only appear when the conditions are right. We’ve provided this table to help you discover the hidden gems within each command.
Is the / Sitecore part of the path optional?
As you may have noticed, the /sitecore portion of the path is unnecessary. This is because the Sitecore item is represented by the root item of the drive master: and is therefore optional. Let’s have a look at the equivalent code in C#.
Is there a limit to the number of items in Sitecore?
The default Sitecore query limit (usually 100 or 260, depending on the version of Sitecore) applies here, so result sets are limited Both Get-ChildItem and Get-Item cmdlets operate directly from the Sitecore content databases, which is a major factor in their performance issues with large item counts.
When to use Sitecore to retrieve an item?
The majority of scripts written with SPE contain one or more of the following commands: Use this to retrieve a single item. Throws an error if the item does not exist. Use when Sitecore query: or fast: is required. May return more than 1 item.