Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / Spe.ShieldsDown.config
Created August 19, 2020 01:38
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
<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 August 14, 2020 20:57
Demonstrates adding environment variables for Sitecore.
# 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}"
<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 July 30, 2020 19:01
Unlock the Sitecore Admin account.
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 July 11, 2020 01:40
A calculator to return the average of the last number of x items. This can be useful when you want to estimate time remaining.
# 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)
@michaellwest
michaellwest / GenerateFormsReport.ps1
Last active June 27, 2020 13:27
Generate a report of forms data using Sitecore PowerShell Extensions.
$selectedForm = Get-Item -Path "master:" -ID ([Sitecore.ExperienceForms.Client.Constants.GeneralConstants]::FormsFolderId)
$props = @{
Parameters = @(
@{Name="selectedForm"; Value=$null; Title="Choose a form to filter out the results"; Tooltip=""; Editor="treelist"; Source="DataSource=$($selectedForm.ItemPath)&DatabaseName=master&IncludeTemplatesForDisplay=Folder,Form&IncludeTemplatesForSelection=Form"; },
@{ Name = "startDate"; Value=[System.DateTime]::Now.AddDays(-30); Title="Start Date"; Tooltip="Earliest submitted entries to return"; Editor="date"; Columns=6; },
@{ Name = "endDate"; Value=[System.DateTime]::Now; Title="End Date"; Tooltip="Latest submitted entries to return"; Editor="date"; Columns=6; }
)
Title = "Forms Report"
@michaellwest
michaellwest / CopyGeoFieldData.ps1
Last active June 29, 2020 01:02
Tips for upgrading Sitecore using SXA and Scriban
# First make your items inherit from /sitecore/templates/System/Geospatial/Coordinate
# Leave the existing IPoi there until after Go Live otherwise the data will be lost (or you have to run the import again)
# TODO : Update the import script to use the new field
# Change to the root ID for items which use the IPoi template
# Careers
#$rootId = "{B8208D4B-C25E-4381-A183-4177E47A9310}"
# POIs
$rootId = "{60365D59-F2F2-4C49-91DA-9C7B046178CF}"
@michaellwest
michaellwest / Find-Renderings-With-Rules.ps1
Created May 24, 2020 14:28
Find home items where a rendering has 1 or more rules applied using Sitecore PowerShell Extensions.
$device = Get-LayoutDevice -Default
$sites = [Sitecore.Configuration.Factory]::GetSiteInfoList()
foreach($site in $sites) {
$isTrackingEnabled = [Sitecore.MainUtil]::GetBool($site.Properties["enableTracking"], $true)
if($isTrackingEnabled -or [string]::IsNullOrEmpty($site.TargetHostName)) { continue }
$homeItem = Get-Item -Path "$($site.RootPath)/$($site.StartItem)".Replace("/sitecore", "master:")
Write-Host "Checking $($homeItem.ItemPath)"
foreach($rendering in $homeItem.Visualization.GetRenderings($device, $false)) {
if($rendering.Settings.Rules.Count -le 0) { continue }
$rendering
@michaellwest
michaellwest / ReadExif.ps1
Created May 16, 2020 03:59
Read EXIF orientation using Sitecore PowerShell Extensions.
# https://exiftool.org/TagNames/EXIF.html
# https://stackoverflow.com/questions/27835064/get-image-orientation-and-rotate-as-per-orientation
# http://fredericiana.com/2013/05/23/imagetwist-exif-rotation-addon/
# https://www.cyotek.com/blog/handling-the-orientation-exif-tag-in-images-using-csharp
enum ExifOrientation {
RotateNoneFlipNone = 1
Rotate90FlipX = 5
Rotate90FlipNone = 6
}
#[System.Drawing.RotateFlipType]::Rotate90FlipNone
@michaellwest
michaellwest / FindDuplicateItemNames.ps1
Last active April 13, 2020 18:25
Find items with a duplicate item name at the same level using Sitecore PowerShell Extensions.
Import-Function -Name Invoke-SqlCommand
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")
$query = @"
SELECT
a.[ID],
a.[Name],
a.[ParentID]
FROM [dbo].[Items] a