Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael michaellwest

  • Texas
View GitHub Profile
@michaellwest
michaellwest / JoinSxaTags.html
Last active Oct 13, 2020
In Sitecore join SxaTags separated by comma using a Scriban template.
View JoinSxaTags.html
{{ if i_item.SxaTags != "" }}
<span>
Department:
</span>
{{ $tags = [] }}
{{ for i_tag in (sc_followmany i_item "SxaTags") }}
{{ $tags[$tags.size] = i_tag | sc_field "Title" }}
{{ end }}
{{ $tags | array.sort | array.join ", " }}
{{ end }}
@michaellwest
michaellwest / ImportRainbowItemBulk.cs
Last active Oct 4, 2020
Sample import command that uses threading for Sitecore PowerShell Extensions.
View ImportRainbowItemBulk.cs
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;
using Kamsar.WebConsole;
using Rainbow.Model;
using Rainbow.Storage.Sc.Deserialization;
using Sitecore.Data;
@michaellwest
michaellwest / CreateRunspaces.ps1
Last active Oct 4, 2020
Create simple runspaces in PowerShell.
View CreateRunspaces.ps1
$watch = [System.Diagnostics.Stopwatch]::StartNew()
# BLOCK 1: Create and open runspace pool, setup runspaces array with min and max threads
$pool = [RunspaceFactory]::CreateRunspacePool(1, [int]$env:NUMBER_OF_PROCESSORS+1)
$pool.Open()
$runspaces = $results = @()
# BLOCK 2: Create reusable scriptblock. This is the workhorse of the runspace. Think of it as a function.
$scriptblock = {
param (
[string]$Data
@michaellwest
michaellwest / ExportAccess.ps1
Created Oct 1, 2020
Export and Import user access using Sitecore PowerShell Extensions
View ExportAccess.ps1
# Use this report to export current access
$users = Get-User -Filter * | Where-Object { $_.Roles.Count -gt 0 }
$records = [System.Collections.ArrayList]@()
foreach($user in $users) {
$record = [PSCustomObject]@{
"Username" = $user.Name
"Roles" = ($user.Roles | Select-Object -ExpandProperty Name) -join ","
}
$records.Add($record) > $null
@michaellwest
michaellwest / DeleteFromPublishingJobQueue.ps1
Created Sep 28, 2020
Remove entries in the Sitecore Publishing Service queue using PowerShell.
View DeleteFromPublishingJobQueue.ps1
Import-Function -Name Invoke-SqlCommand
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")
$query = @"
DELETE TOP (1000)
FROM [dbo].[Publishing_JobQueue]
SELECT COUNT(*) QueueCount
FROM [dbo].[Publishing_JobQueue]
"@
@michaellwest
michaellwest / Spe.ShieldsDown.config
Created Aug 19, 2020
Example to turn off some of the security features for local development with Sitecore PowerShell Extensions. https://alan-null.github.io/2017/01/spe-dev-config
View Spe.ShieldsDown.config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<powershell>
<services>
<remoting>
<patch:attribute name="enabled">true</patch:attribute>
<authorization>
<add Permission="Allow" IdentityType="User" Identity="sitecore\admin" />
</authorization>
</remoting>
@michaellwest
michaellwest / PopulateEnvironmentVariables.ps1
Last active Aug 14, 2020
Demonstrates adding environment variables for Sitecore.
View PopulateEnvironmentVariables.ps1
# Michael West
# Example adding environment variables for use with Sitecore XP 9.3+ and the Publishing Service.
# Be sure to restart IIS every time you make changes.
$appsettingsPrefix = "SITECORE_APPSETTINGS_"
$connectionPrefix = "SITECORE_CONNECTIONSTRINGS_"
$publishingConnectionPrefix = "SITECORE_SITECORE__PUBLISHING__CONNECTIONSTRINGS__"
$databaseServerName = "{REPLACE_WITH_DATABASE_SERVER_NAME}"
$searchServerName = "{REPLACE_WITH_SEARCH_SERVER_NAME}"
View BaseExample.config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"
xmlns:set="http://www.sitecore.net/xmlconfig/set/"
xmlns:role="http://www.sitecore.net/xmlconfig/role/"
xmlns:environment="http://www.sitecore.net/xmlconfig/environment/">
<sitecore role:require="Standalone or ContentManagement">
</sitecore>
</configuration>
@michaellwest
michaellwest / UnlockAdmin.ps1
Created Jul 30, 2020
Unlock the Sitecore Admin account.
View UnlockAdmin.ps1
Import-Function -Name Invoke-SqlCommand
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("core")
$query = @"
SELECT TOP (10) *
FROM [dbo].[aspnet_Membership]
WHERE [IsLockedOut] = '1'
"@
Invoke-SqlCommand -Connection $connection -Query $query
@michaellwest
michaellwest / MovingAverage.ps1
Created Jul 11, 2020
A calculator to return the average of the last number of x items. This can be useful when you want to estimate time remaining.
View MovingAverage.ps1
# Converted from this answer: https://stackoverflow.com/a/44318312/1277533
class AverageCalculator {
[System.Collections.Queue]$Queue
[long]$Total
[int]$Size
AverageCalculator([int]$Size) {
$this.Queue = New-Object System.Collections.Queue
$this.Size = [Math]::Max($Size, 1)
You can’t perform that action at this time.