Skip to content

Instantly share code, notes, and snippets.

$datasource = Get-Item .
$referrers = $datasource | Get-ItemReferrer
$pageOnlyReferrers = $referrers | Where-Object { $_.Name -ne '__Standard Values' } | Sort-Object -Property Name -Unique
$pageOnlyReferrers = $pageOnlyReferrers | Where-Object { $_.Paths.Path -like '/sitecore/content/{site-node}' }
if ($pageOnlyReferrers.Count -eq 0) {
return;
}
@georgechang
georgechang / death.scriban
Last active February 10, 2023 18:01
This is why we can't have nice things
{{
# Get all pages that are nested under the root
# Check if it has a layout (avoids data source object)
# Set flag to true. Show everything if no filter is set.
# Get page filters. If a section has filters, set taxonomy flag to false. At least one field must match selected filters. Set to true #if we find a matching field.
# If the field parsing remains true after checking each field, add the item to an array.
# The array takes the item, and the date field parsed to that the date is a single number, year/month/day.
# After all field and array parsing is done, sort the array by date.
# Loop through the array and render the items.
@michaellwest
michaellwest / PullAllDockerImages.ps1
Last active September 1, 2023 01:28
A convenient PowerShell script to list all the docker images and pull the from the registry.
docker image ls --format "{{json .Repository}},{{json .Tag}},{{json .ID}}" |
ConvertFrom-Csv -Header "Repository","Tag","Id" |
Where-Object { $_.Tag -ne "<none>" -and $_.Repository.Contains("/") } |
ForEach-Object { docker pull "$($_.Repository):$($_.Tag)"}
@peplau
peplau / SPE: Quick Download Tree as Package (Advanced)
Last active November 10, 2022 20:39
SPE: Advanced Quick Download Tree as Package - Allows the user to pick and choose among Linked Items to include in the package as well
Line 1 - Changed the Import-Function Name to Setup-PackageGeneratorAdvanced
Line 5 - Removed as the $path variable was not used
Lines 20-22 - Updated to always show the Links tab, which is now a radiobox
Line 74 - Replaced by the block from lines 75 to 149
Lines 76 to 87 - Replaced by the block from lines 151 to 162
@ErikNoren
ErikNoren / Program.cs
Last active February 27, 2024 18:15
ASP.NET Core 6 configuration settings stored in a SQL database and acts just like appsettings.json
//Snippet from Program.cs which adds the provider and sets up a Settings class to map the settings
using ErikNoren.Configuration;
using TestMvcWebApplication;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddSqlDatabase(config =>
{
//We can get the connection string from previously added ConfigurationProviders to use in setting this up
config.ConnectionString = builder.Configuration.GetConnectionString("DemoDatabase");
@michaellwest
michaellwest / FindRevisionIssues.ps1
Last active May 2, 2024 14:17
Sitecore PowerShell Extensions script to rename items. Workaround for an issue in SXA where items are not published because the revision is missing on the item (even though the Content Editor shows one). Sitecore Support public reference number 522438
$matchedItems = [System.Collections.ArrayList]@()
$revisionFilter = @("9323dec0-9b37-4fae-b87c-2dc12cbea0f2")
Get-ChildItem -Path "master:\media library" -Recurse |
Where-Object { [string]::IsNullOrEmpty($PSItem["__revision"]) -or $revisionFilter -contains $PSItem["__revision"] } |
ForEach-Object { $matchedItems.Add([PSCustomObject]@{"ItemId"=$PSItem.ID; "RevisionId"=$PSItem["__revision"]; "ItemPath"=$PSItem.ItemPath}) > $null }
$matchedItems | Show-ListView
@rminderhoud
rminderhoud / powershell-web-server.ps1
Last active May 4, 2024 14:02 — forked from 19WAS85/powershell-web-server.ps1
A simple web server built with powershell.
# This is a super **SIMPLE** example of how to create a very basic powershell webserver
# 2019-05-18 UPDATE — Created by me and and evalued by @jakobii and the comunity.
# Http Server
$http = [System.Net.HttpListener]::new()
# Hostname and port to listen on
$http.Prefixes.Add("http://localhost:8080/")
# Start the Http Server
@cassidydotdk
cassidydotdk / Build.ps1
Last active May 23, 2021 06:01
Complete Build and Publish Script. Will deploy all projects to publishing target, no HPP required.
param(
[Parameter()]
[switch]$NoBuild,
[Parameter()]
[switch]$NoSync,
[Parameter()]
[string]$CmHost="https://habitatstarterkit.local",
[Parameter()]
[string]$SolutionName="HabitatStarterKit.sln",
[Parameter()]
@kinetiq
kinetiq / SimpleValidator
Created October 27, 2020 21:25
Manually validate any model in .NET Core 3.1
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Ether.Validation
{
public static class SimpleValidator
{
/// <summary>
/// Validate the model and return a response, which includes any validation messages and an IsValid bit.
@michaellwest
michaellwest / ExportAccess.ps1
Created October 1, 2020 17:15
Export and Import user access using Sitecore PowerShell Extensions
# 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