Instantly share code, notes, and snippets.

View BulkCreateItemsWithScriptSessions.ps1
$watch = [System.Diagnostics.Stopwatch]::StartNew()
$sessions = [System.Collections.ArrayList]@()
foreach($i in 1..100) {
$sesh = Start-ScriptSession -ScriptBlock {
New-Item -Path "master:/content/Home/Sample Item" -Name "Sample-$($name)" -ItemType "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}" > $null
} -ArgumentList @{"name"=[ID]::NewID.ToShortID().ToString()} -AutoDispose
$sessions.Add($sesh) > $null
}
View BulkLoadItems-DataBlaster.ps1
$db = Get-Database -Name "master"
$item = $db.GetItem("/sitecore/content/Home/Delete Me")
$item.DeleteChildren()
$template = [Sitecore.Data.Managers.TemplateManager]::GetTemplate("{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", $db)
$bulkLoader = New-Object Sitecore.DataBlaster.Load.BulkLoader
$context = $bulkLoader.NewBulkLoadContext($db.Name)
$action = [Sitecore.DataBlaster.Load.BulkLoadAction]::Update
View FindItemsWithDuplicateItemPaths
$rootId = "{47982199-5497-49DE-8F2D-B10607B5049D}"
$rootItem = Get-Item -Path "master:" -ID $rootId
$rootItem.Axes.GetDescendants() | Initialize-Item |
Group-Object { $_.ItemPath} |
Where-Object { $_.Count -gt 1 } |
Sort-Object -Property Count -Descending |
Select-Object -Property Count, Name
View 00-UnicornFastQueryWarning.txt
44644 13:45:34 WARN [Unicorn] A Fast Query was performed and Unicorn had one or more configurations enabled that used Transparent Sync. Fast Query is not supported with Transparent Sync. Either stop using Fast Query (it's generally regarded as a bad idea in almost every circumstance), or disable Transparent Sync for all configurations.
44644 13:45:34 WARN [Unicorn] The Fast Query was: //*[@@templateid = '{EDA823FC-BC7E-4EF6-B498-CD09EC6FDAEF}']
44644 13:45:34 WARN [Unicorn] The call stack that made the Fast Query was: at Unicorn.Data.DataProvider.UnicornSqlServerDataProvider.QueryFast(String query, CallContext context)
at Sitecore.Data.DataProviders.DataProvider.SelectIDs(String query, CallContext context, DataProviderCollection providers)
at Sitecore.Data.DataManager.SelectItems(String query, Boolean& processed)
at Sitecore.Data.DataManager.SelectItems(String query)
at Sitecore.Data.DefaultDatabase.SelectItems(String query)
at Scms.Foundation.Multisite.SiteResolvers.ScmsEnvironmentSitesR
View RandomItemGenerator.ps1
$selectedRootItem = Get-Item -Path "master:" -ID "{A1D0B3BC-CCDA-41FF-B59A-33AB84BF950B}"
$selectedItemTemplate = Get-Item -Path "master:" -ID "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
$inputCount = 100
$itemNamePrefix = "DeleteMe"
$childCount = $selectedrootItem.Children.Count + 1
$createdItems = [System.Collections.ArrayList]@()
$totalItemCount = $childCount + $inputCount
for($index = $childCount; $index -lt $totalItemCount; $index++) {
$createdItem = $null
View CopyContentWithRainbow.ps1
Import-Module -Name "SPE"
$session = New-ScriptSession -user "admin" -pass "b" -conn "https://spe-a"
$yaml = Invoke-RemoteScript -ScriptBlock {
$homeId = "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"
Get-ChildItem -Path "master:" -ID $homeId -WithParent -Recurse |
ConvertTo-RainbowYaml
} -Session $session
$session2 = New-ScriptSession -user "admin" -pass "b" -conn "https://spe-b"
View SPE-Dialog-With-Commands.ps1
# Be sure to update this ID to whichever script you want to execute when the link is clicked.
$scriptId = "{6EAF681D-5D87-4C43-B279-356A8B9A15CF}"
$item = Get-Item -Path "."
$script = Get-Item -Path "master:" -ID $scriptId
$command = "item:executescript(id=$($item.ID),db=$($item.Database.Name),script=$($script.ID),scriptDb=$($script.Database.Name))"
$options = [ordered]@{"Download Sample"=$command;"View Documentation"=$command;}
$props = @{
Parameters = @(
View Update-SPE-Module-Icons.ps1
<#
.SYNOPSIS
Sitecore PowerShell Extensions 5.0 uses new icons. This script is designed to update
your existing modules to use the new icon.
.DESCRIPTION
The SPE module changes the icon when you enable/disable the module. Only disabled modules
will automatically take the new icon. This is script helps by updating all of the icons
for enabled modules. Alternatively, you can go through and disable then enable the modules.
#>
View Tls-1.2-Security.ps1
if (![Net.ServicePointManager]::SecurityProtocol.HasFlag([Net.SecurityProtocolType]::Tls12)) {
[Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12
}
View PredicateBuilder-Attempt.ps1
Add-Type -AssemblyName "Sitecore.ContentSearch"
Add-Type -AssemblyName "Sitecore.ContentSearch.Linq"
class ExtendedSearchResultItem : Sitecore.ContentSearch.SearchTypes.SearchResultItem {
[Sitecore.ContentSearch.IndexField("_latestversion")]
[bool]$IsLatestVersion
}
# String
$methodContains = [string].GetMethod("Contains")