Skip to content

Instantly share code, notes, and snippets.

View MartinMiles's full-sized avatar

Martin Miles MartinMiles

View GitHub Profile
@MartinMiles
MartinMiles / Show-LargestMediaItems.ps1
Created May 30, 2025 19:07
Shows all the media sorted by the size, descending, from the largest to the smallest
# It will show all the media sorted by the size, descending, from the largest to the smallest
# 1) Mount master: PSDrive if it’s not present
if (-not (Get-PSDrive -Name master -ErrorAction SilentlyContinue)) {
New-PSDrive -Name master -PSProvider Sitecore -Root "\" -Database master | Out-Null
}
# 2) Cache the master database object
$database = [Sitecore.Configuration.Factory]::GetDatabase("master")
# Batch Create / Update Rendering Definitions for Zont Feature
# ------------------------------------------------------------
# ❶ Mount master: drive if absent
if (-not (Get-PSDrive -Name master -ErrorAction SilentlyContinue)) {
New-PSDrive -Name master -PSProvider Sitecore -Root "/" -Database "master" -ErrorAction Stop | Out-Null
}
# ❷ Grab master DB and base item
$db = [Sitecore.Configuration.Factory]::GetDatabase("master")
$basePath = "/sitecore/layout/Renderings"
@MartinMiles
MartinMiles / Set-LayoutItemForPagePresentation.ps1
Last active June 3, 2025 06:59
Sets Layout item for the page's presentation details (on a shared layout field) without modifying/resetting the rest of presentation/renderings
param(
[string]$PageItemPath = "/sitecore/content/Zont/Habitat/Home/AAA",
[string]$LayoutItemPath = "/sitecore/layout/Layouts/Foundation/JSS Experience Accelerator/Presentation/JSS Layout"
)
# 1. Mount "master:" drive if missing
if (-not (Get-PSDrive -Name master -ErrorAction SilentlyContinue)) {
try {
New-PSDrive -Name master -PSProvider Sitecore -Root "/" -Database "master" -ErrorAction Stop | Out-Null
Write-Host "📁 Mounted master: drive."
@MartinMiles
MartinMiles / Rebind-TopLevelPlaceholders.ps1
Last active June 15, 2025 08:41
Processes all the rendering for a page and rebinds a top level component from one to another (say, from `page-layout` to `headless-main`) including those nested
# -----------------------------------------------------------
# Inline Script for Sitecore PowerShell ISE:
# Replace Multiple Placeholders for Renderings
# Target Item: Default is /sitecore/content/Zont/Habitat/Home/AAA
# DB: master
# - Processes Standard Values, Shared Layout, and Final Layout.
# - Replaces three placeholder pairs:
# $OldPlaceholder1 → $NewPlaceholder1
# $OldPlaceholder2 → $NewPlaceholder2
# $OldPlaceholder3 → $NewPlaceholder3
# -----------------------------------------------
# Script: Get-FinalLayoutXml-ForPage.ps1
# Purpose: Retrieve the merged (“Final”) layout XML
# for a given page item—combining shared,
# versioned, and standard-values presentations.
# Target Item: /sitecore/content/Zont/Habitat/Home/AAA
# Prerequisites: Run inside Sitecore PowerShell ISE or
# using Sitecore PowerShell Extensions context.
# -----------------------------------------------
@MartinMiles
MartinMiles / Get-PlaceholdersToComponentsLayoutJson-REMOTING.ps1
Created June 4, 2025 20:03
Used to help mapping rederings to the placeholders
param(
[string]$itemPath = "/sitecore/content/Zont/Habitat/Home/AAA"
)
Set-Location -Path $PSScriptRoot
$config = Get-Content -Raw -Path ./config.LOCAL.json | ConvertFrom-Json
# Write-Output "ConnectionUri: $($config.connectionUri)"
# Write-Output "Username : $($config.username)"
# Write-Output "SPE Remoting Secret : $($config.SPE_REMOTING_SECRET)"
@MartinMiles
MartinMiles / Slice-HtmlToComponents.ps1
Last active June 4, 2025 22:07
Runs on a host machine, pulls a web page from legacy site, slices components into react/next.js tsx files under the same paths/subfolders as was done for cshtml, pulls the components hierarchy and sets placeholders as per original names
<#
.SYNOPSIS
Slices a fully rendered Sitecore HTML page into individual Next.js component `.tsx` files,
based on the <!-- start-component='…' --> / <!-- end-component='…' --> markers and
by calling Get-Layout.ps1 (which now returns JSON) for the layout hierarchy.
.PARAMETER Url
The URL of the rendered page. Defaults to http://rssbplatform.dev.local/aaa
.PARAMETER ItemPath
@MartinMiles
MartinMiles / Create-SingleJsonRenderingWithParametersTemplate.ps1
Last active June 6, 2025 23:00
Create a Json rendering and also an XM Cloud compatible rendering parameters template for it. Inherit existing parameters templates
param(
[string]$ParametersTemplateId = "{A2A233A1-6701-48A9-B5F8-EFEAB74B655F}"
)
$ErrorActionPreference = "Stop"
# 1. Mount master drive if needed
if (-not (Get-PSDrive -Name master -ErrorAction SilentlyContinue)) {
New-PSDrive -Name master -PSProvider Sitecore -Root "/" -Database "master" -ErrorAction Stop | Out-Null
}
$ErrorActionPreference = 'Stop'
# ❶ Mount master: drive if absent
if (-not (Get-PSDrive -Name master -ErrorAction SilentlyContinue)) {
New-PSDrive -Name master -PSProvider Sitecore -Root "/" -Database "master" -ErrorAction Stop | Out-Null
}
# ❷ Get master database
$db = [Sitecore.Configuration.Factory]::GetDatabase('master')
if (-not $db) { throw 'Cannot get master database.' }
@MartinMiles
MartinMiles / Get-LayoutServicePlaceholderIDs-ForXmCloudRenderings-REMOTING.ps1
Last active June 9, 2025 10:57
We need to find which nested placeholders are defined within renderings on a page, this script does it (say, for `ArticleAsideLeft` it returns `col-wide-1-0-1`). We need this later to set `Layout Service Placeholders` field on XM Cloud renderings
Set-Location -Path $PSScriptRoot
# Load connection settings
$config = Get-Content -Raw -Path ./config.LOCAL.json | ConvertFrom-Json
# Import SPE and start a remote session
Import-Module -Name SPE
$session = New-ScriptSession -ConnectionUri $config.connectionUri `
-Username $config.username `
-SharedSecret $config.SPE_REMOTING_SECRET